#include <stdio.h>
void main(void)
{
char srt[100]={"hello world"},buf[100]={'\0'};
int i=0;
FILE *fp
fp=fopen("1.txt","w+");
if(fp==NULL)
{
printf("文件打开失败");
return;
}
else
{
fputs(str,fp);
rewind(fp);
fgts(buf,100,fp);
}
fclose(fp);
printf("buf:%s\n",buf);
}
#include <stdio.h>
void main(void)
{
chsr ch;
FILE *fp;
fp=fopen("test.txt","w");
printf("请输入一串字符,以'!'结束:\n");
whlie (1)
{
ch=getche();
if (ch=='!')
{
break;
}
if(ch>='a'&&ch<='z')
{
ch-=32;
}
fputc(ch,fp);
}
folose(fp)
}
/*#include<stdio.h>
void main(void)
{
char str[50]={"hello world"},str2[50]={'\0'};
FILE *fp;
int i=0;
fp=fopen("ni.txt","w+");
if(fp==NULL)
{
printf("打开文件失败");
return;
}
else
{
fprintf(fp,"%s",str);
rewind(fp);
fscanf(fp,"%s",str2);
}
fclose(fp);
printf("%s\n",str2);
}*/