I am printing the first 128 ASCII characters in a file and then trying to read those characters printing their ASCII decimal value.
I tried using fread() and fscanf() functions but both stop after reading first 25 characters.
#include <stdio.h>
int main()
{
int i;
char ch;
FILE *fp;
fp=fopen("a.txt","w+");
for(i=0;i<128;i++)
{
fprintf(fp,"%c",i);
}
fseek(fp,0,SEEK_SET);
while(fread(&ch, sizeof(char), 1, fp))
printf("%d\n",ch);
return 0;
}
I expect the output to be the decimal value of the first 128 ASCII characters but the actual output only have decimal value of first 25 ASCII characters.