【发布时间】:2017-03-22 13:19:00
【问题描述】:
当我尝试从名为“file1”的文件中读取输入时,我的程序正确显示 文件中的字符数,但采用无法识别的字符格式。 下面是代码
#include <stdio.h>
#include <stdlib.h>
void db_sp(FILE*);
int main(int argc,char *argv[])
{
FILE *ifp,*ofp;
if(argc!=2) {
fprintf(stderr,"Program execution form: %s infile\n",argv[0]);
exit(1);
}
ifp=fopen(argv[1],"r");
if (ifp==NULL) printf("sdaf");
//ofp=fopen(argv[2],"w+") ;
db_sp(ifp);
fclose(ifp);
//fclose(ofp);
return 0;
}
void db_sp(FILE *ifp)
{
char c;
while(c=getc(ifp) !=EOF) {
//printf("%c",c);
putc(c,stdout);
if(c=='\n' || c=='\t' || c==' ')
printf("%c",c);
}
}
【问题讨论】:
-
请在您的问题中发布代码。
-
你能显示你的文件包含什么吗?您的印刷品打印什么?