sizeof(char* result) will always result in 4 (32 bit target) or 8 (64 bit target)
Unless the actual length of result
matches 3 or 7 bytes (considering also the NULL
terminator) the wrong length information will cause fwrite (result, sizeof (result), 1, fh);
to fail. Replace this with:
fwrite (result, strlen(result) + 1, 1, fh);
Aside: (not part of the primary problem) Regarding the following:
char buf[100];
sprintf(buf,"%s.%s","outputFile",extension);
Even though sprintf()
does append a
termination to the resulting buffer for a successful call, as a rule it is a good habit to initialize. buffers to be used in string functions. Eg: :
char buf[100] = {0};//populates entire memory location with `nul` characters.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…