/*#include<stdio.h>
void main(void)
{
char str[50]={"hello world"},str2[20]={'\0'};
FILE *fp;
int i=0;
fp=fopen("hello.txt","r");
if(fp==NULL)
{
printf("文件打开失败");
return;
}
else
{
fgets(str2,100,fp);
}
fclose(fp);
printf("%s\n",str2);
}*/
#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);
}*/
}
include<stdio.h>
void main(void)
{
char ch;
FILE *fp;
fp=fopen("test.txt","w")
printf("请输入一串字符");
if(fp==NULL)
{
printf("文件打开失败");
return;
}
}
else
{
while(1)
{
ch=getchar();
if(ch=='!')
{
break;
}
if(ch>='a'&&ch<='z')
{
ch-=32
}
fputc(ch,fp);
}
fclose(fp);
}
总结:今天又学习了新的知识