With fputs, is there a way to adjust where its puts the data? I need to put data in a column in another file.
With fputs, is there a way to adjust where its puts the data? I need to put data in a column in another file.
Sure. You just change the second argument. For example, fputs("slappy", stdout); will write to the standard output device, whereas fputs("slappy", fp); will write to whatever fp points to.
If you understand what you're doing, you're not learning anything.
I understand that but I need to put "slappy" in about 30 spaces to the left of the margin of the file that fp points to.
Or you can just prepend 30 spaces to the string. Or you can put a 30-character string filled with spaces in the file before writing "slappy". There's a dozen different ways to do it.Code:{ int i; for(i = 0;i < 30;++i) fputc(' ', fp); fputs("slappy", fp); }
If you understand what you're doing, you're not learning anything.
Cool, thanks!!!
You can't just use fprint with a width specifier instead of using fputs?
I'm just saying, is it a requirement that you use fputs and can't use fprintf?Code:// Write "slappy" with 30 spaces in front of it. fprintf(fp,"%*s",30+strlen("slappy"),"slappy");
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
sprintf is your friend. Followed by a simple:
Assuming of course that you don't simply just use fprintf in the first place.Code:fputs( buf, fp );
Quzah.
Hope is the first step on the road to disappointment.