C Puts() Without Newline
Answer :
Typically one would use fputs() instead of puts() to omit the newline. In your code, the
puts(input);
would become:
fputs(input, stdout);
puts()
adds the newline character by the library specification. You can use printf
instead, where you can control what gets printed with a format string:
printf("%s", input);
You can also write a custom puts function:
#include <stdio.h> int my_puts(char const s[static 1]) { for (size_t i = 0; s[i]; ++i) if (putchar(s[i]) == EOF) return EOF; return 0; } int main() { my_puts("testing "); my_puts("C puts() without "); my_puts("newline"); return 0; }
Output:
testing C puts() without newline
Comments
Post a Comment