Solved

Selection

Posted on 1997-02-18
3
209 Views
Last Modified: 2010-04-15
Write a program that takes an integer keyed in from the terminal and extracts and displays each digit of the integer in English. For example if the user type in 780, Seven Eight Zero will be displayed on the screen.(Without using pointers)
0
Comment
Question by:leekoon
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
rbr earned 100 total points
ID: 1249503
Try this programm:
#include <stdio.h>
int main(int argb, char *argv[])
{
   unsigned number;
   char buffer[100];
   int i;
   
   scanf ("%u", &number);
   sprintf (buffer, "%u", number);
   for (i=0;i<strlen(buffer);i++) {
      switch (buffer[i]) {
          case '0':
            printf ("Zero ");
          break;  
          case '1':
          printf ("One ");
          break;  
          case '2':
          printf ("Two ");
          break;  
          case '3':
          printf ("Three ");
          break;  
      case '4':
          printf ("Four ");
      break;  
      case '5':
          printf ("Five ");
      break;  
      case '6':
          printf ("Six ");
      break;  
      case '7':
          printf ("Seven ");
      break;  
      case '8':
          printf ("Eight ");
      break;  
      case '9':
          printf ("Nine ");
      break;  
       }
   }
   printf ("\n");
   return 0;
   
}

If you want to parse longer integer numbers just read it directly in the buffer by using scanf ("%s",buffer);

Robert B. Rossmann


0
 

Author Comment

by:leekoon
ID: 1249504
Edited text of question
0
 
LVL 10

Expert Comment

by:rbr
ID: 1249505
Where do I use pointers? The only pointer I need is in the scanf function and there you must use a pointer.

Please explain me exactly what you want.


Robert B. Rossmann
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now