alpha-numeric to numeric program

The following program should take a phone number with alpha-numeric and convert it to numeric. The problem i am having is that it give me an syntax error saying that i am messing ; in line 10 and saying that x is not defined. here is the program.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
     
    #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]); 
    } 
    
   }
 }    

     
    


Also can anyone tell me if i am doing the program correctly i pretty much created an array and asked there user enter in the number and did a switch to convert to number and print it out. If i am doing something wrong other then the problem i have stated can anyone let me know. THANKS.
Last edited on
IIRC in C you need to declare your variables at the top. You cannot mix statements between.
1
2
3
4
5
6
#define SIZE 30

void convNum( char *phoNum)
{
    phoNum[SIZE];  //statement
    int x=0; //error: declaration cannot happen here 

Edit: C90 forbids it. C99 seems to allow it.
Last edited on
thanks for the help, I fixed the problem and the program is giving a linker error. Can someone please help me out. THANKS.
Last edited on
Post the error then.
Topic archived. No new replies allowed.