Click here to Skip to main content
15,891,375 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: destroy a dialog in a MFC application Pin
Rajesh R Subramanian9-May-08 3:02
professionalRajesh R Subramanian9-May-08 3:02 
GeneralRe: destroy a dialog in a MFC application Pin
toxcct9-May-08 3:09
toxcct9-May-08 3:09 
GeneralRe: destroy a dialog in a MFC application Pin
Rajesh R Subramanian9-May-08 3:31
professionalRajesh R Subramanian9-May-08 3:31 
AnswerRe: destroy a dialog in a MFC application Pin
toxcct9-May-08 3:08
toxcct9-May-08 3:08 
AnswerRe: destroy a dialog in a MFC application Pin
tom groezer9-May-08 3:20
tom groezer9-May-08 3:20 
GeneralRe: destroy a dialog in a MFC application Pin
tom groezer9-May-08 3:26
tom groezer9-May-08 3:26 
GeneralRe: destroy a dialog in a MFC application Pin
Mark Salsbery9-May-08 6:15
Mark Salsbery9-May-08 6:15 
Questionfputc or fgetc returning odd results Pin
Klempie9-May-08 2:03
Klempie9-May-08 2:03 
Hi there.

I've got a bit of a weird one here. I'm writing a pair of compression/decompression programs for a varsity assignment and there is something odd happening in the transmission of integers. Basically, the spec is that they must be stored big endian so I wrote these:

// writes an int in big endian to file stream<br />
bool writeintbigendian ( FILE * file, int number )<br />
{<br />
	unsigned char *c = ( unsigned char * ) &number;<br />
<br />
	for ( short i = sizeof ( int ) - 1; i > -1; i-- )<br />
	{<br />
		if ( fputc ( c[i], file ) ==EOF )<br />
			return false;<br />
	}<br />
<br />
	return true;<br />
};<br />
<br />
// reads a big endian int from stream<br />
int readintbigendian ( FILE * file )<br />
{<br />
	int readInt = 0;<br />
	unsigned char * c = ( unsigned char * ) &readInt;<br />
<br />
	for ( short i = sizeof ( int )-1; i > -1; i--)<br />
	{<br />
		c[i] = (unsigned char) fgetc(file);	<br />
	}<br />
<br />
	return readInt;<br />
};


Now there is a dictionary of ints that are written out using writeintbigendian and then the ints are read in using readintbigendian to reconstruct it. The process reads in like 42 ints and then bombs out where the value of -230 was supposed to have been written. The reason being because -1 is read instead of -230.

To narrow down the problem, I stopped the debugger in the write section to find out what it was writing. The arguments to fputc are the following in order:

-230 = |255|255|255|26|

when it comes to reading it out using fgetc it ends up with

-1 = |255|255|255|255|

Clearly either the read function is reading the last byte in incorrectly or the write is writing it incorrectly but I can't figure out which. It's certainly not a synching issue either because the previous 42 values all get transmitted fine and there are no other intermediate steps when reading or writing. It's literally going through a for loop on both sides calling the respective functions. Obviously, I'd like to avoid delving into binary formats of files here.
AnswerRe: fputc or fgetc returning odd results Pin
Klempie9-May-08 2:28
Klempie9-May-08 2:28 
GeneralRe: fputc or fgetc returning odd results Pin
Rajkumar R9-May-08 2:37
Rajkumar R9-May-08 2:37 
GeneralRe: fputc or fgetc returning odd results Pin
Klempie9-May-08 2:40
Klempie9-May-08 2:40 
GeneralRe: fputc or fgetc returning odd results Pin
Klempie9-May-08 2:50
Klempie9-May-08 2:50 
AnswerRe: fputc or fgetc returning odd results [modified] Pin
Rajkumar R9-May-08 3:38
Rajkumar R9-May-08 3:38 
GeneralRe: fputc or fgetc returning odd results Pin
Klempie9-May-08 4:15
Klempie9-May-08 4:15 
GeneralRe: fputc or fgetc returning odd results Pin
Rajkumar R9-May-08 4:21
Rajkumar R9-May-08 4:21 
GeneralRe: fputc or fgetc returning odd results Pin
Klempie9-May-08 4:28
Klempie9-May-08 4:28 
AnswerRe: fputc or fgetc returning odd results Pin
Klempie9-May-08 4:48
Klempie9-May-08 4:48 
GeneralRe: fputc or fgetc returning odd results Pin
Rajkumar R9-May-08 5:05
Rajkumar R9-May-08 5:05 
GeneralRe: fputc or fgetc returning odd results Pin
Rajkumar R9-May-08 4:56
Rajkumar R9-May-08 4:56 
AnswerRe: fputc or fgetc returning odd results Pin
Klempie9-May-08 5:06
Klempie9-May-08 5:06 
GeneralRe: fputc or fgetc returning odd results Pin
Rajkumar R9-May-08 5:10
Rajkumar R9-May-08 5:10 
AnswerRe: fputc or fgetc returning odd results Pin
toxcct9-May-08 3:06
toxcct9-May-08 3:06 
GeneralRe: fputc or fgetc returning odd results Pin
Klempie9-May-08 3:38
Klempie9-May-08 3:38 
GeneralRe: fputc or fgetc returning odd results Pin
toxcct9-May-08 3:45
toxcct9-May-08 3:45 
GeneralRe: fputc or fgetc returning odd results Pin
Klempie9-May-08 3:47
Klempie9-May-08 3:47 

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.