Click here to Skip to main content
15,887,746 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionProblem writing large character array to a file Pin
fourierman28-May-06 13:20
fourierman28-May-06 13:20 
AnswerRe: Problem writing large character array to a file [modified] Pin
Chris Losinger28-May-06 13:23
professionalChris Losinger28-May-06 13:23 
GeneralRe: Problem writing large character array to a file [modified] Pin
bob1697228-May-06 14:12
bob1697228-May-06 14:12 
AnswerRe: Problem writing large character array to a file [modified] Pin
bob1697228-May-06 14:17
bob1697228-May-06 14:17 
GeneralRe: Problem writing large character array to a file [modified] Pin
fourierman28-May-06 14:35
fourierman28-May-06 14:35 
GeneralRe: Problem writing large character array to a file [modified] Pin
Chris Losinger28-May-06 16:06
professionalChris Losinger28-May-06 16:06 
AnswerRe: Problem writing large character array to a file Pin
kakan28-May-06 20:49
professionalkakan28-May-06 20:49 
GeneralRe: Problem writing large character array to a file Pin
fourierman29-May-06 10:15
fourierman29-May-06 10:15 
Regarding the null terminating character being embedded within the source/custom resource, I'm having some difficulty getting fwrite to continue past embedded 0x00 values in my data...

Someone posted earlier:
It acted like it continued beyond the end of the array until it came across the zero byte in memory. I put the "\0" or the 0x00 and it stopped exactly where I told it too. This raises the question, if that array is supposedly a hex representation of an exe, how are you getting away without stumbling across 0x00 somewhere in the binary string? this is one of the reason they tell us to encode binary data when using a null terminated string to contain it.

My code:
char * cStr = reinterpret_cast< char *>(lpVoid);
cStr = strncat(cStr, "\0", 1);
printf("size of cStr%d\n", sizeof(cStr));
FILE * stream;
if( (stream = fopen( "fread.out", "w" )) != NULL )
{
int num_write = 0;
num_write = fwrite( cStr, sizeof( cStr ), 1, stream );
printf( "Wrote items: %d\n", num_write );
fclose( stream );
}

Results:

follwing were writing sizeof(cStr) - 1 (not wanting to write the trailing null to our output file):

testing: 4d 5a 90 as input, output: 4d 5a 90 (OK)
testing: 4d 5a 90 00 as input, output: 4d 5a 90
testing: 4d 5a 90 00 03 as input, output: 4d 5a 90
testing: 4d 5a 90 03 as input: output: 4d 5a 90

writing sizeof(cStr) :
4d 5a 90 -> 4d 5a 90 00
4d 5a 90 00 -> 4d 5a 90 00
4d 5a 90 00 03 -> 4d 5a 90 00 (stripped trailing character)

Anyone have any suggestions on how to proceed?
How will the program know the difference between the trailing null at the end of the string versus embedded nulls?
GeneralRe: Problem writing large character array to a file Pin
kakan29-May-06 19:39
professionalkakan29-May-06 19:39 
Questionhow can i read an excell sheet from visual c# Pin
raniam28-May-06 12:48
raniam28-May-06 12:48 
AnswerRe: how can i read an excell sheet from visual c# Pin
bob1697228-May-06 12:53
bob1697228-May-06 12:53 
QuestionCListCtrl subitem problem Pin
Ivan Cachicatari28-May-06 11:15
Ivan Cachicatari28-May-06 11:15 
AnswerRe: CListCtrl subitem problem [modified] Pin
bob1697228-May-06 11:45
bob1697228-May-06 11:45 
QuestionHow i remove a part of a string Pin
Immunity1828-May-06 9:29
Immunity1828-May-06 9:29 
AnswerRe: How i remove a part of a string Pin
bob1697228-May-06 9:43
bob1697228-May-06 9:43 
GeneralRe: How i remove a part of a string Pin
Immunity1828-May-06 9:45
Immunity1828-May-06 9:45 
AnswerRe: How i remove a part of a string Pin
anwer_skk28-May-06 16:33
anwer_skk28-May-06 16:33 
GeneralRe: How i remove a part of a string Pin
bob1697228-May-06 16:47
bob1697228-May-06 16:47 
GeneralRe: How i remove a part of a string Pin
anwer_skk28-May-06 17:15
anwer_skk28-May-06 17:15 
GeneralRe: How i remove a part of a string Pin
bob1697228-May-06 17:33
bob1697228-May-06 17:33 
GeneralRe: How i remove a part of a string Pin
ThatsAlok28-May-06 22:54
ThatsAlok28-May-06 22:54 
QuestionCPropertyPagae Pin
ftsOne28-May-06 8:56
ftsOne28-May-06 8:56 
AnswerRe: CPropertyPagae Pin
bob1697228-May-06 10:50
bob1697228-May-06 10:50 
GeneralRe: CPropertyPagae Pin
ftsOne28-May-06 17:04
ftsOne28-May-06 17:04 
GeneralRe: CPropertyPagae Pin
bob1697228-May-06 17:57
bob1697228-May-06 17:57 

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.