Click here to Skip to main content
16,007,687 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: load jpg file in C++ Pin
Paresh Chitte8-Mar-07 20:05
Paresh Chitte8-Mar-07 20:05 
AnswerRe: load jpg file in C++ Pin
Paresh Chitte8-Mar-07 21:07
Paresh Chitte8-Mar-07 21:07 
QuestionStrange private boolean member behaviour inside a public function (long question) Pin
Joan M8-Mar-07 10:37
professionalJoan M8-Mar-07 10:37 
QuestionRe: Strange private boolean member behaviour inside a public function (long question) Pin
Mark Salsbery8-Mar-07 12:14
Mark Salsbery8-Mar-07 12:14 
AnswerRe: Strange private boolean member behaviour inside a public function (long question) Pin
Joan M8-Mar-07 20:06
professionalJoan M8-Mar-07 20:06 
GeneralRe: Strange private boolean member behaviour inside a public function (long question) Pin
Mark Salsbery9-Mar-07 6:47
Mark Salsbery9-Mar-07 6:47 
GeneralRe: Strange private boolean member behaviour inside a public function (long question) Pin
Joan M9-Mar-07 7:00
professionalJoan M9-Mar-07 7:00 
Questionfread switching endianness on unformatted binary file Pin
regzim8-Mar-07 9:42
regzim8-Mar-07 9:42 
I'm losing sleep over this...
Sorry in advance about the long question

I've got an unformatted binary(.mid) file I want to display as text. When I use fscanf, like this:

*****************************

#include <stdio.h>
int main ()
{
void *list;
int i;
FILE * pFile;

pFile = fopen ("C:/Moondance.mid", "rb");
for(i=1; i<5; i++) //read 4 chars
{
fread(&list, 1, 1, pFile);
printf("%c ", list);
}
list=0;
for(i=1; i<5; i++) // read 4 bytes of decimals
{
fread(&list, 1, 1, pFile);
printf("%x ", list);
}
fclose (pFile);
return 0;
}
************************



it shows a byte at a time like this:

M T h d 0 0 0 6
(file header) (next chunk size)

where 0 0 0 6 is really 00 00 00 06, a 4-byte number

But when I try to replace the "for" number reader code with this:

******
fread(&list, 4, 1, pFile);
printf("%x ", list);
******

I get:

M T h d 6000000

It seems to have switched endedness or read each byte in the wrong order into the pointer.
I want it to print out as just decimal "6"
help?

regzim
QuestionRe: fread switching endianness on unformatted binary file Pin
David Crow8-Mar-07 9:52
David Crow8-Mar-07 9:52 
AnswerRe: fread switching endianness on unformatted binary file Pin
Chris Losinger8-Mar-07 11:10
professionalChris Losinger8-Mar-07 11:10 
GeneralRe: fread switching endianness on unformatted binary file Pin
regzim8-Mar-07 19:01
regzim8-Mar-07 19:01 
GeneralRe: fread switching endianness on unformatted binary file Pin
cp98768-Mar-07 19:27
cp98768-Mar-07 19:27 
GeneralRe: fread switching endianness on unformatted binary file Pin
Chris Losinger9-Mar-07 1:14
professionalChris Losinger9-Mar-07 1:14 
GeneralRe: fread switching endianness on unformatted binary file Pin
regzim9-Mar-07 8:16
regzim9-Mar-07 8:16 
GeneralRe: fread switching endianness on unformatted binary file Pin
Chris Losinger9-Mar-07 8:29
professionalChris Losinger9-Mar-07 8:29 
GeneralRe: fread switching endianness on unformatted binary file Pin
regzim9-Mar-07 9:21
regzim9-Mar-07 9:21 
GeneralRe: fread switching endianness on unformatted binary file Pin
regzim9-Mar-07 9:24
regzim9-Mar-07 9:24 
GeneralRe: fread switching endianness on unformatted binary file Pin
Chris Losinger9-Mar-07 9:33
professionalChris Losinger9-Mar-07 9:33 
QuestionComparing Values Pin
Herboren8-Mar-07 8:00
Herboren8-Mar-07 8:00 
AnswerRe: Comparing Values Pin
Maximilien8-Mar-07 8:03
Maximilien8-Mar-07 8:03 
QuestionRe: Comparing Values Pin
David Crow8-Mar-07 9:43
David Crow8-Mar-07 9:43 
AnswerRe: Comparing Values Pin
Herboren8-Mar-07 10:38
Herboren8-Mar-07 10:38 
QuestionRe: Comparing Values Pin
David Crow8-Mar-07 10:58
David Crow8-Mar-07 10:58 
AnswerRe: Comparing Values Pin
Herboren8-Mar-07 11:11
Herboren8-Mar-07 11:11 
GeneralRe: Comparing Values Pin
David Crow8-Mar-07 16:51
David Crow8-Mar-07 16:51 

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.