#include<stdio.h>
#include<ctype.h>
void main() {
FILE* p1, * p2; char ch;
p1 = fopen("d1.dat", "r");
p2 = fopen("d2.dat", "w");
while (feof(p1) == 0)
{
ch = fgetc(p1);
if (isalpha(ch))
fputc(ch, p2);
}
fclose(p1); fclose(p2);
}
d1.dat里面有字符吗
供参考:
#include<stdio.h>
#include<ctype.h>
int main()
{
FILE *fp1,*fp2;
char ch;
fp1=fopen("d1.txt","r");
if(fp1 == NULL){
printf("open file fail!\n");
}
else{
fp2=fopen("d2.txt","w");
if(fp2 == NULL){
printf("open file fail!\n");
}
else{
while(feof(fp1)==0)
{
ch = fgetc(fp1);
if(isalpha(ch))
fputc(ch,fp2);
}
fclose(fp2);
}
fclose(fp1);
}
return 0;
}