1、 fputs用于将字符串输入到文件中,而fgets则相反,从文件中读取字符串
2、使用举例:用fputs将“hello,world”输入到刚创建的文件hello.txt中,再用fgets读出
#include <stdio.h>
#define LENGTH 100
int main(void)
{
FILE *fd;
char str[LENGTH];
//创建一个文件
fd = fopen("hello.txt","w+");
//往文件里面写入字符串“"hello.world"
if(fd)
{
fputs("hello,world",fd);
}
//关闭文件
fclose(fd);
//再次打开文件,并读出所有字符串
fopen("hello.txt","r");
fgets(str,LENGTH,fd);
//输出到标准输出设备
printf("%s\n",str);
//关闭文件
fclose(fd);
}