当前位置: C语言 -- 标准库 -- <stdio.h> -- fputs

fputs函数


概要:
#include <stdio.h>
int fputs(const char * restrict s,
     FILE * restrict stream);

描述:

该函数将参数s指向的字符串写入参数stream指向的流,终止空字符不会被写入。


参数:
const char * restrict s

char类型指针,指向将要写入流的字符串。

FILE * restrict stream

FILE类型指针,指向写入字符串的输出流。


返回值:

如果发生写入错误,函数返回EOF;否则函数返回非负值。


范例:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
/*函数fputs范例*/

#include <stdio.h>

int main(void)
{
    FILE *pFile;
    const char str[] = "All for one, one for all.";

    if(pFile=fopen("gch.txt", "w"))
        fputs(str, pFile);
    
    fclose(pFile);

    return 0;
}


结果:

创建一个名为gch.txt的文件,并向其写入:

All for one, one for all.


相关内容:
fputc 将字符写入输出流的函数。
putc 将字符写入输出流的函数。
putchar 将字符写入标准输出流的函数。
puts 将字符串写入标准输出流的函数。