i have an assignment to write a C program suing Pointer to count the character or word found in a particular string. i already did it, but i cannot enter the word, its fine with the character. can anybody help me? thx :)
#include <stdio.h>
#include <string.h>
int main (int argc, char**argv)
{
int i, letterCount;
char LetterToMatch;
char *c;
char string[220];
printf("Enter a string (220 character max): ");
for (*(c=string)=0; *(c - 1) != '\n';)
*c++ = (char) getchar();
*(c - 1)=0;
printf("Enter any character or words: ");
scanf ("%c", &LetterToMatch);
printf("\nIn this string: \"%s\"\n", string);
for (letterCount=0, c=string; *c; ++c)
letterCount += (*c == LetterToMatch) ? 1 : 0;
printf("the character '%c' appears %d time%s.\n", LetterToMatch, letterCount, letterCount == 1 ?"":"s");
return(0);
}