FILE *fp1=fopen("The_Holy_Bible.txt","r");
FILE *fp2=fopen("The_Holy_Bible_Res.txt","w"); // 没有文件会自动创建一个
char str[N]="",ch='\n';
int index=0;
while(memset(str,0,sizeof(str)),fgets(str,N,fp1)!=NULL) //读一行
{
for(index=0;index<strlen(str);index++)
{
if( str[index]>='A'&&str[index]<='Z' )
{
str[index] += 32;
}
else if(str[index]==':'||str[index]==','||str[index]=='.'||str[index]=='['||str[index]==']'||str[index]=='?'||str[index]==';')
{
str[index]=' ';
}
else
{
continue;
}
}
fputs(str,fp2);
}
|
FILE *fp1=fopen("The_Holy_Bible.txt","r");
FILE *fp2=fopen("The_Holy_Bible_Res.txt","w"); // 没有文件会自动创建一个
char str[N]="";
int index=0;
while(memset(str,0,sizeof(str)),fread(str,sizeof(char),N-1,fp1)!=NULL) //一次读N-1个,从0开始算。
{
for(index=0;index<strlen(str);index++)
{
if( str[index]>='A'&&str[index]<='Z' )
{
str[index] += 32;
}
else if(str[index]==':'||str[index]==','||str[index]=='.'||str[index]=='['||str[index]==']'||str[index]=='?'||str[index]==';')
{
str[index]=' ';
}
else
{
continue;
}
}
fwrite(str,sizeof(char),N-1,fp2);
}
|
char ch;
FILE *fp1=fopen("The_Holy_Bible.txt","r");
FILE *fp2=fopen("The_Holy_Bible_Res.txt","w"); // 没有文件会自动创建一个
while( (ch=fgetc(fp1)) != EOF )
{
if(ch>='A'&&ch<='Z')
{
ch += 32;
fputc(ch,fp2);
}
else if( ch==':'||ch==','||ch=='.'||ch=='['||ch==']'||ch==';'||ch=='?')
{
ch=' ';
fputc(ch,fp2);
}
else
{
fputc(ch,fp2);
}
}
|