Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a full string to a file?

I'm programming in Windows right now, but portable code would be welcomed too.

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

like image 877
Anaya Avatar asked Dec 01 '25 21:12

Anaya


1 Answers

Use fputs instead:

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

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!