Objective of this program is to read binary data from a file and print it.
Code:
#include <stdio.h>
void readFile(void);
int main(){
readFile();
return 0;
}
void readFile(void){
FILE *fp;
char ch;
if((fp = fopen("newfile","rb"))==NULL){
printf("Error reading.\n");
return;
}
while(!feof(fp)){
if(fread(&ch, sizeof ch, 1, fp)!=1){
printf("Error.\n");
return;
}
putchar(ch);
}
fclose(fp);
}
But When I Run This Code First It Print "Error." Then Rest Of The File.Say In My File I Have "I AM HUMAN", It Prints "Error. HUMAN"!!
I Cant Figure Out Whats Wrong In The readFile() Function.It seems right to me.