Monday 2 July 2018

c - While Loop doesn't stop executing

The "while" in my code doesn't stop running even when I type " ^Z "
it's supposed to stop since the EOF exists.
Any idea why?


 #define NUM_OF_GRADES 10
int maxInArray();
int main()
{ char ch1;
int grades[NUM_OF_GRADES];
int grade;
printf("Please enter a character:");
printf("\n");
scanf("%c",&ch1);
printf("Please enter grades:");
printf("\n");
while (scanf("%d",&grade)!=EOF)
{
grades[grade-1]++;
}
return 0;
}

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...