>I change it, but I have tried it because I don't have a compiler in my computer.
Whenever possible, it's best to copy-and-paste the actual code to your post; retyping can introduce its own errors.
Code:
#include <stdio.h>
int main()
{
int alpha2number(char data[]) ; /* missing semicolon */
/* But why (attempt to) prototype a function you don't define or use? */
char value[ strlen(data) ]; /* I'd avoid this and stick with C90 */
/* You don't define 'data', so this is an error (even in C++^H^H99). */
int x = 0;
printf("Please enter a phone number: \n");
fflush(stdout); /* my suggestion */
scanf("%d", &x); /* Check the return value for success? */
while(data[x] != '\0') {
switch(data[x]) {
case 'a': case 'b': case 'c': /* Got the colon here... */
value[x] = '2'; /* Aren't you making a string? */
break;
case 'd': case 'e': case 'f': /* ...but here the last colon is missing. */
value[x] = '3'; /* Put characters in a string. */
break;
/*...*/
It would appear that you are taking an input string that would be in the format "ABC-DEFG" and want to transform it into its equivalent phone number string, "222-3334". Most of a solution has been posted already. Let's just say we use a function; I might do something like this.
Code:
#include <stdio.h>
#include <ctype.h>
char *foo(char *dst, const char *src)
{
char *start;
for ( start = dst; *src != '\0'; ++dst, ++src )
{
switch ( tolower(*src) )
{
case 'a': case 'b': case 'c': *dst = '2'; break;
case 'd': case 'e': case 'f': *dst = '3'; break;
case 'g': case 'h': case 'i': *dst = '4'; break;
case 'j': case 'k': case 'l': *dst = '5'; break;
case 'm': case 'n': case 'o': *dst = '6'; break;
case 'p': case 'q': case 'r': case 's': *dst = '7'; break;
case 't': case 'u': case 'v': *dst = '8'; break;
case 'w': case 'x': case 'y': case 'z': *dst = '9'; break;
default: *dst = *src; /* copy non-alphabetic characters as-is */
}
}
*dst = '\0';
return start;
}
int main(void)
{
const char number[] = "Get-Help";
char result[32];
foo(result, number);
printf("number = \"%s\", result = \"%s\"\n", number, result);
puts(foo(result, "(800) EAT-SPIT"));
return 0;
}
/* my output
number = "Get-Help", result = "438-4357"
(800) 328-7748
*/
Please read up on [code] [/code] tags to make future postings more readable.