Re: I have a problem in my study
- From: "Cong Wang" <xiyou.wangcong@xxxxxxxxx>
- Date: 30 Oct 2006 03:30:18 -0800
Richard Heathfield wrote:
Cong Wang said:
qazwsx746@xxxxxxxx wrote:
I use operating systems of windows xp ,
and compiler is trubo c 3.0
when I input data,the following program can't be exited.
what happen to this program?
Is the wrong with the compiler?
#include <stdio.h>
main(int argc,char *argv[])
{ FILE *fp;
void filecopy(FILE *,FILE *);
if (argc==1)
filecopy(stdin,stdout);
else
while (--argc>0)
if ((fp=fopen(*++argv,"r"))==NULL) {
printf("cat:can't open %s\n",*argv);
return 1;
} else {
filecopy(fp,stdout);
fclose(fp);
}
return 0;
}
void filecopy(FILE *ifp,FILE *ofp)
{int c;
while ((c=getc(ifp))!=EOF)
putc(c,ofp);
}
Well, first, if you know function main is int. Add the type befor its
name. Do NOT leave that position blank.
That's a minor style point, and not his problem.
But I think it's important. ;-p
Second, 'stdin' doesn't has an
EOF until you press Ctrl+d, thus you can't exit.
Wrong.
Well, I forgot he used Window$. In fact, Win uses <Ctrl-Z><CR> as EOF.
I am sorry, I can't afford a Windows and know little about it. ;-(
.
- References:
- I have a problem in my study
- From: qazwsx746
- Re: I have a problem in my study
- From: Cong Wang
- Re: I have a problem in my study
- From: Richard Heathfield
- I have a problem in my study
- Prev by Date: Re: I have a problem in my study
- Next by Date: Re: how to use bit operation to do \sqrt(n)
- Previous by thread: Re: I have a problem in my study
- Next by thread: Re: I have a problem in my study
- Index(es):
Relevant Pages
|
|