职称申报基本情况表:在C语言中如何把资料存进文件里

来源:百度文库 编辑:高校问答 时间:2024/04/29 09:05:51

从键盘输入一行字符,写入一个文件, 再把该文件内容读出显示在屏幕上。你把从键盘上输入的东西变成你要保存的东西就可以了。
#include<stdio.h>
main()
{
FILE *fp;
char ch;
if((fp=fopen("string","wt+"))==NULL)
{
printf("Cannot open file strike any key exit!");
getch();
exit(1);
}
printf("input a string:\n");
ch=getchar();
while (ch!='\n')
{
fputc(ch,fp);
ch=getchar();
}
rewind(fp);
ch=fgetc(fp);
while(ch!=EOF)
{
putchar(ch);
ch=fgetc(fp);
}
printf("\n");
fclose(fp);
}

设置一下保存路径