Sunday, December 4, 2011

How to read a binary file in C ?

I want to know what function from which header I must use to read a binary file.





I will need to know how big a file is in byte. Then I want to move N byte into a char * variable.





For example what I must do to move 5000 byte from "Data.txt" to char * DataChar ?|||#include %26lt;stdio.h%26gt;


FILE *fp;


fp = fopen("Data.txt", "rb");


fseek(fp, 0, SEEK_END);


filesize = ftell(fp);


rewind(fp);


fread(DataChar, 5000, 1, fp);


fclose(fp);|||use the function fopen() with the last parameter as "rb" (read, binary).

No comments:

Post a Comment