1从文件中读一行
#include
int main(int argc, char *argv[])
{
FILE *oldfile, *newfile;
//oldfile="a.txt";
//newfile="b.txt";
oldfile=fopen("a.txt","r");
if(oldfile == NULL){
printf("the fild is open error");
return -1;
}
else{
// printf("the a.txt is " oldfile);
printf("aa");
}
newfile=fopen("b.txt", "w ");
if(newfile == NULL){
printf("the b.txt is error");
}
char p[1024];
while (fgets(p,sizeof(p),oldfile)!= NULL){
fputs(p , newfile);
}
fclose(oldfile);
fclose(newfile);
return 0;
}
2 读一个字符
#include
int main(int argc, char *argv[])
{
FILE *fp1,*fp2;
fp1=fopen("b.c", "w ");
if(fp1 == NULL){
perror("fopen");
}
else{
printf("ok !!");
}
fputs("a", fp1);
fputs("b", fp1);
fputs("0xff", fp1);
rewind(fp1);
// fputs(EOF, fp1);
fp2=fopen("b1.c", "w ");
if(fp2 == NULL){
perror("fopen");
}
else{
printf("b1.c is ok \n");
}
int c;
while((c=fgetc(fp1))!=EOF){
fputc(c, fp2);
}
fclose(fp1);
fclose(fp2);
return 0;
}
阅读(152) | 评论(0) | 转发(0) |