CKTIS / C
fputs — C23 stream function
`fputs(s, stream)` from `<stdio.h>` writes every character of string `s` before its terminating null byte; it writes neither the terminator nor an automatic newline. It returns a nonnegative value on success or `EOF` on failure.
Version: C23
Syntax
int fputs(const char * restrict s, FILE * restrict stream);fputs(s, stream) from <stdio.h> writes every character of string s before its terminating null byte; it writes neither the terminator nor an automatic newline. It returns a nonnegative value on success or EOF on failure.
The example calls fputs("red", stream) and fputs("+blue", stream), rewinds, and reads the eight stored characters. Output 1 red+blue demonstrates successful status and the absence of an added separator or terminator in the stream.
s must designate a valid null-terminated string accessible during the call, and stream must permit output; violating these requirements is undefined. Check EOF plus later fflush or fclose, because buffering can expose failure later. For an explicit newline, write fputs("\n", stream) or use fputc.
Examples
#include <stdio.h>
int main(void){FILE*s=tmpfile();if(!s)return 1;int ok=fputs("red",s)>=0&&fputs("+blue",s)>=0;rewind(s);char b[9]={0};if(fread(b,1,8,s)!=8){fclose(s);return 1;}printf("%d %s\n",ok,b);return fclose(s)==0?0:1;}
Result
1 red+blue
The example calls `fputs("red", stream)` and `fputs("+blue", stream)`, rewinds, and reads the eight stored characters. Output `1 red+blue` demonstrates successful status and the absence of an added separator or terminator in the stream.