I have a problem with reading the EOF character for the last input in C
j=0;
while(*(name2+j)!='\n'){
if(*(name2+j) == ' '){
j++;
continue;
}
d[tolower(*(name2+j))]++;
j++;
}
For the last input, there is no new line character, the value of j is getting set to very large number for a very small string. So, to consider the end of file, i modified the while condition to
while(*(name2+j)!='\n' && (*(name2+j))!=EOF)
but still i am having the same problem. Can someone tell if i am missing something here ? Thanks.
EOFis an integer value outside the range of achar(since its very purpose is to indicate that nocharis present), so if you want to be able to compare a value toEOF, then you need to retrieve and store that value as anintrather than as achar.