Thread: alpha-numeric to numeric program

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    20

    alpha-numeric to numeric program

    The following program is converting alpha-numeric phone number to numeric. The problem i am having is that it is giving me a link error and i am not sure why. Can anyone help out Thanks.


    Code:
       #include <stdio.h>#include <ctype.h>
    
    
    
    
    #define SIZE 30
    
    
    void convNum( char *phoNum)
    {   
        int x=0; 
        phoNum[SIZE];  
        
        printf("Enter the phone number:"); 
    
    
    
    
        while (gets(phoNum)!=NULL)
        {
           
         switch(toupper(phoNum[x]))
         {
         case 'A': 
         case 'B': 
         case 'C': 
              phoNum[x]=2; 
              break; 
         case 'D': 
         case 'E': 
         case 'F': 
              phoNum[x]=3; 
              break; 
         case 'G': 
         case 'H': 
         case 'I': 
              phoNum[x]=4; 
              break; 
         case 'J': 
         case 'K': 
         case 'L': 
              phoNum[x]=5; 
              break; 
         case 'M':
         case 'N': 
         case 'O': 
              phoNum[x]=6; 
              break; 
         case 'P': 
         case 'Q': 
         case 'R': 
         case 'S': 
              phoNum[x]=7; 
              break; 
         case 'T': 
         case 'U': 
         case 'V': 
              phoNum[x]=8; 
              break; 
         case 'W': 
         case 'X': 
         case 'Z': 
              phoNum[x]=9; 
              break; 
              }
         for (x; x<SIZE; x++)
        {
            printf("%c", phoNum[x]); 
        } 
        
       }
     }

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    The entry point of a C program is a function named main(), which you are required to provide. main() calls other functions as needed in order to implement required functionality. The code you have shown does not provide a main() function. That will cause a linker error.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > The problem i am having is that it is giving me a link error and i am not sure why.
    Neither do we, since you didn't actually post the actual error messages.

    If you're compiling / linking with the GCC toolchain, it could be warning you (again) that gets() is deprecated.
    But when you do resolve your linker issue, please do the world a favour by typing in say a 60 character phone number, just for the hell of it.

    > Can anyone help out
    At this moment, it seems doubtful
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking if a var is numeric?
    By Glauber in forum C++ Programming
    Replies: 21
    Last Post: 05-18-2008, 12:51 PM
  2. My numeric analyzer (2)
    By siavoshkc in forum C++ Programming
    Replies: 11
    Last Post: 07-27-2007, 03:32 PM
  3. My numeric analyzer
    By siavoshkc in forum C++ Programming
    Replies: 22
    Last Post: 07-15-2007, 09:54 AM
  4. C++: Converting Numeric String to Alpha String
    By JosephCardsFan in forum C++ Programming
    Replies: 3
    Last Post: 02-16-2005, 07:07 AM
  5. Numeric to string help
    By StupidQuestion in forum C++ Programming
    Replies: 2
    Last Post: 01-08-2003, 12:56 PM