This is what happens when I run it.
It should be :
Enter Phone Number: CAlLatT
Numeric Form: 2255288
This is what happens when I run it.
It should be :
Enter Phone Number: CAlLatT
Numeric Form: 2255288
the variable 'i' needs to be reset back to 0 before the while loop. Right now the while loop is being skipped over completely because the for loop is incrementing 'i' to the end of the string.
so should I add curly braces before the while loop and after the i++?
Nothing Changes
Does it have to do with the braces? Or its totally something else?
Code:#include <stdio.h> int main() { char N[20]; int i=0; printf("Enter phone number: "); scanf("%s" ,N); printf("Numeric Form:"); for(i=0; i<=strlen(N); i++){ if(N[i]>=97&&N[i]<=122) N[i]=N[i]-32; } { while (N[i] != '\0') switch (N[i]) { case '.' : case ',' : case '@' : printf("1"); break; case 'A' : case 'B' : case 'C' : printf("2"); break; case 'D' : case 'E' : case 'F' : printf("3"); break; case 'G' : case 'H' : case 'I' : printf("N4"); break; case 'J' : case 'K' : case 'L' : printf("5"); break; case 'M' : case 'N' : case 'O' : printf("6"); break; case 'P' : case 'Q' : case 'R' : case 'S' : printf("7"); break; case 'T' : case 'U' : case 'V' : printf("8"); break; case 'W' : case 'X' : case 'Y' : case 'Z' : printf("9"); break; printf("%c", N[i]); } i++; } return(0); }
Refer back to Post#17
also change your curly braces to be after the while loop condition instead of behind it.
So i have a mistake somewhere with the braces?
should beCode:{ while (N[i] != '\0')
Code:while (N[i] != '\0'){
I tired, nothing changes
did you reset i back to 0 before the while loop like post #17 suggested??
well i changed the braces, which would make the i go back to 0 and then to the while loop (like post 26) but it didn't work.
show me how changing the braces will make the i go back to 0. It won't. The 'i' is coming out of the for loop and it's value is whatever the strnlen(N) is. therefore it is not 0. you need to manually set it to 0 before the while loop and after the for loop.