0

Hi all,
I wish to write the contents of a large char array into a file. I open the file for writing and say, fp is the pointer to the file.
and I write :
fprintf(fp,"%s",buff);
Does fprintf write the whole array into the file or is there any inbuilt restriction.Because ,the final expeced file is not containing the whole array, the file writing process stops at a certain stage..actually this is a part of a bigger prog and I am speculating that the problem might lie here.. Can some one explain the internal working of this procedure..
thanks

4
Contributors
4
Replies
5
Views
11 Years
Discussion Span
Last Post by Dave Sinkula
0

It will write the contents of buff up the the null. Assuming that it is a char array as opposed to a string, and the char array contains embedded nulls, you will get less output than expected. Perhaps use fwrite instead.

0

Try with:
fwrite (fp,i*sizeof(char),1,buff);
i is a number of characters that you want to write to file.
You have declaration of this function in stdio.h.
i also can be a strlen(fp).
strlen declaration is in string.h

0

>> fwrite (fp,i*sizeof(char),1,buff);

there is no need for sizeof(char) because it is guaranteed by the language to always be 1 regardless of platform or compiler. Just makes less typing and fewer characters to read :mrgreen:

fwrite (fp,i,1,buff);

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.