Solved

Selection

Posted on 1997-02-18
3
234 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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 opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

789 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