关于getc的实验

#include "Stdio.h" #include "Conio.h" #include int main() { test1(); getch(); return 0; } test1(){ char ch; FILE *fp; FILE *outfp; char str[800]; char cc=' '; long count=0; char *filename="c://upwing//word2a.txt"; char *filename2="c://upwing//word2b.txt"; if((fp=fopen(filename,"rb"))==NULL){ printf("can't open %s/n",filename); getch(); exit(1); } if((outfp=fopen(filename2,"ab"))==NULL){ printf("can't open %s/n",filename2); getch(); exit(1); } while(ch=getc(fp),ch!=EOF){ putc(ch,outfp); printf("%X ",ch); str[count]=ch; count++; } str[count]='/0'; /*puts("/n/n lichen de shu chu:/n/n"); */ /*puts(str); */ if(fclose(fp)!=0){ printf("close file failed 1/n"); } if(fclose(outfp)!=0){ printf("close file failed 2/n"); } printf("/nfile %s has %ld characters/n",filename,count); getch(); } test2(){ int ch; FILE *outfp; char str[800]="1234567890/t1234567890/r/nABCDEFGHIJKLMN/r/n,.//r/n樃晄?堈?恖?/r/nAAAAABBBBBCCCCC"; char *filename2="c://upwing//word2a.txt"; int n; str[64]=0xFF; if((outfp=fopen(filename2,"wb"))==NULL){ printf("can't open %s/n",filename2); getch(); exit(1); } for(n=0;n<800;n++){ if(str[n]=='/0'){ break; } putc(str[n],outfp); } if(fclose(outfp)!=0){ printf("close file failed 2/n"); } printf("/nfile %s has %ld characters/n",filename2,n); }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值