C stdio fputs() 函数

定义和用法

fputs() 函数将字符串写入文件。

fputs() 函数定义在 <stdio.h> 头文件中。

实例

将字符串写入文件:

FILE *fptr;

// 以写入模式打开文件
fptr = fopen("filename.txt", "w");

// 将字符串写入文件
fputs("Hello World!", fptr);

fclose(fptr);

语法

fputs(const char * str, FILE * fptr);

参数

参数 描述
str 必需。包含要写入字符串的字符数组。
fptr 必需。文件指针,通常由 fopen() 函数创建。

技术细节

返回:

如果函数成功,返回一个非负 int 值。

如果发生错误,返回常量 EOF