How to write a full line to a file?

I am programming on Windows right now, but portable code would also be welcome.

What I'm using now is fwrite(4), but this function requires the maximum number of elements that will be written to the file. I can use it strlen(1)here, but I would like to know if there is a better way to do this.

+3
source share
3 answers

Use fputs instead:

FILE * f = fopen( "myfile.txt", "w" );
fputs( "Hello world\n", f );
+7
source

You can use fputs, but using functions that require writing is safer (buffer overflow).

, , fwrite, .

0

.

0
source

Source: https://habr.com/ru/post/1731752/


All Articles