English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

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 ?

2007-10-26 17:39:44 · 2 answers · asked by seed of eternity 6 in Computers & Internet Programming & Design

I will prefer the code to be written in C not C++.

2007-10-26 17:43:50 · update #1

2 answers

#include
FILE *fp;
fp = fopen("Data.txt", "rb");
fseek(fp, 0, SEEK_END);
filesize = ftell(fp);
rewind(fp);
fread(DataChar, 5000, 1, fp);
fclose(fp);

2007-10-27 03:48:43 · answer #1 · answered by Anonymous · 0 0

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

2007-10-27 07:30:28 · answer #2 · answered by justme 7 · 0 0

fedest.com, questions and answers