返回值
该函数返回一个非负值,否则返回错误EOF。
示例
以下示例显示fputs()函数的用法-
#include <stdio.h>
int main () {
FILE *fp;
fp = fopen("file.txt", "w+");
fputs("This is c programming.", fp);
fputs("This is a system programming language.", fp);
fclose(fp);
return(0);
}
让我们编译并运行以上程序,这将创建具有以下内容的文件file.txt-
This is c programming.This is a system programming language.
现在,让我们使用以下程序查看以上文件的内容:
#include <stdio.h>
int main () {
FILE *fp;
int c;
fp = fopen("file.txt","r");
while(1) {
c = fgetc(fp);
if( feof(fp) ) {
break ;
}
printf("%c", c);
}
fclose(fp);
return(0);
}
让我们编译并运行以上程序以产生以下结果-
This is c programming.This is a system programming language.