| fgetc() 和 fputc() 函数每次只能读写一个字符,速度较慢;实际开发中往往是每次读写一个字符串或者一个数据块,这样能明显提高效率。 
 写字符串函数 fputsfputs() 函数用来向指定的文件写入一个字符串,它的用法为:int fputs( char *str, FILE *fp );str 为要写入的字符串,fp 为文件指针。写入成功返回非负数,失败返回 EOF。例如:
 char *str = "http://193.112.175.132/discuz/forum.php";FILE *fp = fopen("D:\\demo.txt", "at+");fputs(str, fp);
 
 表示把把字符串 str 写入到 D:\\demo.txt 文件中。
 
 【示例】向上例中建立的 d:\\demo.txt 文件中追加一个字符串。
 #include<stdio.h>int main(){    FILE *fp;    char str[102 = {0}, strTemp[100];    if( (fp=fopen("D:\\demo.txt", "at+")) == NULL ){        puts("Fail to open file!");        exit(0);    }    printf("Input a string:");    gets(strTemp);    strcat(str, "\n");    strcat(str, strTemp);    fputs(str, fp);    fclose(fp);    return 0;}
 
 运行程序,输入C 语言学习,打开 D:\\demo.txt,文件内容为:
 http://193.112.175.132/discuz/forum.phpC 语言学习
 
 |