basically, this program will ask the user to write a line of text, and analyze the character in that line of text if its exist or not.
ex :
Code:
enter line of text : abra kadabra
'a' was found
'b' was found
'c' was not found
.
.
.
.
but i have problems with my code, can someone please point out my mistakes.
so, i use array to store the characters, but having problems using them.
this is my code so far :
Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#define MAXLINE 50
int main (void)
{
char string[MAXLINE];
char *alphabet[26] = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
int i;
printf ( "Please enter a line of text ( maximum %d characters ) :", sizeof(string) );
fgets (string, sizeof(string), stdin);
for ( i=0; i <=20 ; i++) {
if ( strchr ( string, alphabet[i] ) != NULL ) {
printf("\'%c\' was found in \"%s\".\n", alphabet[i], string );
}
else {
printf ("\'%c\' was not found in \"%s\".\n", alphabet[i], string);
}
}
getchar();
return 0;
}