we know that puts automatically provides a newline character after the string and fputs doesn't do so. but i was thinking that is it possible to have a newline character before the string while using puts or fputs, like we use in printf.
we know that puts automatically provides a newline character after the string and fputs doesn't do so. but i was thinking that is it possible to have a newline character before the string while using puts or fputs, like we use in printf.
You mean like: puts("\nThis is on a line by itself."); ?
If you understand what you're doing, you're not learning anything.
yes. does this work? and let's say that i declare a string variable name then does puts("\n"name) works?
Try it and see if it does what you want.
Nope, the language doesn't allow concatenating strings together like that, no matter whether you're using puts, some other function or no function whatsoever. That sort of concatenation only works with literals, which are the things you put in double quotes " ". You need printf if you're mixing literals and variables.and let's say that i declare a string variable name then does puts("\n"name) works?
You clearly didn't finish reading my post:
Not sure if this is what you intended, but PRENL(name) will always produce "\nname" regardless of the contents of the name variable (or lack of variable). Try it and see for yourself.Code:puts( "\n" "foo" " " "bar" ); or #define TOSTR(s) #s #define PRENL(s) "\n" TOSTR(s) puts( PRENL( name ) ); /* where name is not a variable, it will be quoted to a literal */