I manage to write:
Code:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
char * alphaTable[] = {
"Alpha",
"Bravo",
"Charlie",
"Delta",
"Echo",
"Foxtrot",
"Golf",
"Hotel",
"India",
"Juliet",
"Kilo",
"Lima",
"Mike",
"November",
"Oscar",
"Papa",
"Quebec",
"Romeo",
"Sierra",
"Tango",
"Uniform",
"Victor",
"Whiskey",
"Xray",
"Yankee",
"Zulu",
NULL
};
void strtoupper(char *s)
{
while (*s)
{
if ((*s >= 'a') && (*s <= 'z'))
*s -= ('a'-'A');
s++;
}
}
char * findMatch(char *table[], char c)
{
int i;
for(i=0; table[i] != NULL; i++)
{
if ( table[i][0] == c) // if first character matches
{
return table[i];
}
}
returnNULL;
}
int main()
{
int i;
char sentace;
printf("Write down your sentace \n");
scanf("%c", &sentace);
char input [] = "Hello 2 you!.";
strtoupper(input); // convert all letters to caps
for (i=0;input[i]!=0;i++)
{
// take characters from the input string
char c = input[i];
// and find matching first letter in the alphaTable
char * result = findMatch(alphaTable,c);
if(result)
{
printf(" %s",result);
}
else// NOT A LETTER
{
if (isdigit(c)) // number
{
int num = c-'0'; // a short cut: get a number
int j;
printf(" ");
for(j=0;j<num;j++) // nothing printed for 0!
{
printf("%s","*");
}
}
else// everything else is printed as is
{
printf("%c",c);
}
}
}
return 0;
}
but it works only for "Hello 2 you" and I want my program to work for any sentence not just "hello 2 you "