用fputs() 函数来向指定的文件写入一个字符串

原创
2016/04/10 22:53
阅读数 888
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
  FILE *fp;
  char str[102] = {0}, strTemp[100];

  if((fp=fopen("testfile", "a+")) == NULL){
    printf("Cannot open file!\n");
    exit(1);
  }
  printf("Input a string:");
  gets(strTemp, fp);
  strcat(str, "\n");
  strcat(str, strTemp);
  fputs(str, fp);

  fclose(fp);
  return 0;
}


展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
1 收藏
1
分享
返回顶部
顶部