Click here to Skip to main content
15,918,808 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow does fscanf in C/C++ work? Pin
cshs1007-May-04 1:21
cshs1007-May-04 1:21 
AnswerRe: How does fscanf in C/C++ work? Pin
Iain Clarke, Warrior Programmer7-May-04 1:37
Iain Clarke, Warrior Programmer7-May-04 1:37 
GeneralRe: How does fscanf in C/C++ work? Pin
Anonymous7-May-04 1:40
Anonymous7-May-04 1:40 
AnswerRe: How does fscanf in C/C++ work? Pin
Dominik Reichl7-May-04 1:39
Dominik Reichl7-May-04 1:39 
GeneralRe: How does fscanf in C/C++ work? Pin
Anonymous7-May-04 1:58
Anonymous7-May-04 1:58 
GeneralRe: How does fscanf in C/C++ work? Pin
Dominik Reichl7-May-04 2:19
Dominik Reichl7-May-04 2:19 
GeneralRe: How does fscanf in C/C++ work? Pin
jmkhael7-May-04 2:29
jmkhael7-May-04 2:29 
AnswerRe: How does fscanf in C/C++ work? Pin
Garth J Lancaster7-May-04 1:48
professionalGarth J Lancaster7-May-04 1:48 
hmm .. not sure I'd be using fscanf here .. you also havnt said 'what you wish to interpret the first two bytes as, ie a long, char values etc'

I dont have my dev machine up, but I guess what you're asking for is :-

char str [2];
fscanf (pFile, "%c%c", str);

however, I'd be more inclined to use fread(), here's a full example


int main () {
FILE * pFile;
long lSize;
char * buffer; // For two chars as in this example could just use
// static char buffer[2];

lSize = 2;

pFile = fopen ( "myfile.bmp" , "rb" );
if (pFile==NULL) exit (1);

// allocate memory to contain # chars we want
// bit of an overkill in this case
buffer = (char*) malloc (lSize);
if (buffer == NULL) exit (2);

// copy the file into the buffer.
fread (buffer,1,lSize,pFile);

// do something with buffer here


// terminate
fclose (pFile);
free (buffer);
return 0;

}


GeneralRe: How does fscanf in C/C++ work? Pin
Anonymous7-May-04 2:00
Anonymous7-May-04 2:00 
GeneralCOleControl Pin
asv7-May-04 0:44
asv7-May-04 0:44 
QuestionGetInternetFileVersionInfo API? Pin
eqmule7-May-04 0:42
eqmule7-May-04 0:42 
AnswerRe: GetInternetFileVersionInfo API? Pin
Iain Clarke, Warrior Programmer7-May-04 1:43
Iain Clarke, Warrior Programmer7-May-04 1:43 
GeneralReports Generation (Advice Required) Pin
Imtiaz Murtaza7-May-04 0:20
Imtiaz Murtaza7-May-04 0:20 
GeneralProblem with calling stack window Pin
HansGanter6-May-04 23:08
HansGanter6-May-04 23:08 
GeneralRe: Problem with calling stack window Pin
Jens Doose7-May-04 2:46
Jens Doose7-May-04 2:46 
GeneralCString How Big Pin
sweep1236-May-04 22:05
sweep1236-May-04 22:05 
GeneralRe: CString How Big Pin
Hesham Amin6-May-04 22:17
Hesham Amin6-May-04 22:17 
GeneralRe: CString How Big Pin
sweep1237-May-04 0:48
sweep1237-May-04 0:48 
GeneralRe: CString How Big Pin
David Crow7-May-04 3:00
David Crow7-May-04 3:00 
GeneralRe: CString How Big Pin
J.B.23-Jun-04 7:19
J.B.23-Jun-04 7:19 
GeneralRe: CString How Big Pin
David Crow23-Jun-04 7:40
David Crow23-Jun-04 7:40 
GeneralCString questions Pin
deecasas6-May-04 22:01
deecasas6-May-04 22:01 
GeneralRe: CString questions Pin
Anonymous6-May-04 22:24
Anonymous6-May-04 22:24 
GeneralRe: CString questions Pin
deecasas6-May-04 22:31
deecasas6-May-04 22:31 
GeneralRe: CString questions Pin
jmkhael6-May-04 22:33
jmkhael6-May-04 22:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.