儲存用fwrite()來完成,建立用fopen()來完成。示例程式碼如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<stdio.h>
int main()
{
char year[10],month[5],day[5];
printf("輸入年、月、日:\n");
gets(year);
gets(month);
gets(day);
char file_name [256] = {0};
printf("輸入要建立的檔名:");
gets(file_name);
FILE *fp=fopen(file_name,"at+");
if(fp==NULL)
printf("can"t create file!");
return 0;
}
fprintf(fp,"%s年%s月%s日",year,month,day);
fclose(fp);
儲存用fwrite()來完成,建立用fopen()來完成。示例程式碼如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<stdio.h>
int main()
{
char year[10],month[5],day[5];
printf("輸入年、月、日:\n");
gets(year);
gets(month);
gets(day);
char file_name [256] = {0};
printf("輸入要建立的檔名:");
gets(file_name);
FILE *fp=fopen(file_name,"at+");
if(fp==NULL)
{
printf("can"t create file!");
return 0;
}
fprintf(fp,"%s年%s月%s日",year,month,day);
fclose(fp);
return 0;
}