OP is using wrong method to size fwrite()
, amongst other small errors.
If "array of char pointers storing 8186 bytes" means
1 each char
array has 8186 significant bytes of data, use size 8186.
2 each char
array is a NUL terminated string, then a test needs to occur to insure each is at least length 6. Not sure what this 6 is all about.
Note: size_t fwrite ( const void * ptr, size_t size, size_t count, FILE * stream )
I suspect that the OP's - 6
is causing a problem when strlen(ptr[i])
is less than 6. This would make the negative difference a very large size_t
, which is usually unsigned for count
in fwrite()
.
for(int i = 0; i < 64048; i++){ // start at 0
if(ptr[i] != NULL){
int result;
result = fwrite(ptr[i], 1, 8186, file);
if (result != 8186) ; handle error;
// or
size_t len = strlen(ptr[i]) + 1; /// Add 1 for the NUL byte
if (len < 6) ; handle error of whatever the OP's 6 is about.
result = fwrite(ptr[i], 1, len, file);
if (result != len) ; handle error;
free(ptr[i]);
}
}