alpha-numeric to numeric program

This is a discussion on alpha-numeric to numeric program within the C Programming forums, part of the General Programming Boards category; The following program is converting alpha-numeric phone number to numeric. The problem i am having is that it is giving ...

  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,662
    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, Sunshine, 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
    32,851
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 01:51 PM
  2. My numeric analyzer (2)
    By siavoshkc in forum C++ Programming
    Replies: 11
    Last Post: 07-27-2007, 04:32 PM
  3. My numeric analyzer
    By siavoshkc in forum C++ Programming
    Replies: 22
    Last Post: 07-15-2007, 10: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21