Code:#include <stdio.h> #define EOL '\0' int main(int argc, const char * argv[]) { char sent[50]; int i=0; int cnt=0; char charac; puts("Please enter a sentence"); scanf(" %[^\n]",sent); puts("Please enter the character to be checked"); charac=getchar(); while (sent[i]!=EOL) { if(sent[i]==charac) { ++cnt; ++i; } else ++i; } printf("\nCHARACTER OCCURRED %d TIMES",cnt); return 0; }
hey guys,
I'm trying to write a program that accepts a character from the user to compute the number of times the character appears in an inputted sentence. However, the compiler completely ignores the
getchar function. So i tried putting the getchar function above the scanf and this time it works!!
Can anyone explain this???



LinkBack URL
About LinkBacks



