以附加方式打开文件,输入数据,关闭文件。
#include<stdio.h> #include<stdlib.h> int main() { FILE *fp = NULL; fp = fopen("test.txt","a+"); if(fp == NULL) { printf("cannot open file"); return -1; } char c[]="22.33,42"; char d[] = {'2','3','.','1','4',',','4','1'}; fprintf(fp, "%s\n",c); fprintf(fp,"%s\n",d); fclose(fp); fp = NULL; return 0; }