我的学习有问题 [英] I have a problem in my study

查看:71
本文介绍了我的学习有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用windows xp的操作系统,

和编译器是trubo c 3.0

当我输入数据时,以下程序无法退出。 />
这个程序会发生什么?

编译器有问题吗?


#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);

返回1;

}其他{

filecopy(fp,stdout);

fclose(fp);

}

返回0;

}

void filecopy(FILE * ifp,FILE * ofp)

{int c;

while((c = getc(ifp))!= EOF)

putc(c,ofp);

}

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);
}

推荐答案


qa ******* @ eyou.com 写道:

我使用windows xp的操作系统,

和编译器是trubo c 3.0

当我输入数据时,以下程序无法退出。

这个程序会发生什么?

编译器有问题吗?


#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:不能打开%s \ n,* argv);

返回1;

}否则{

filecopy(fp,stdout);

fclose(fp);

}

返回0;

}

void filecopy(FILE * ifp,FILE * ofp)

{int c;

while((c = get c(ifp))!= EOF)

putc(c,ofp);

}
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);
}



嗯首先,如果你知道函数main是int。添加类型为

名称。不要将该位置留空。第二,'stdin''没有

EOF,直到你按Ctrl + d,因此你不能退出。

Well, first, if you know function main is int. Add the type befor its
name. Do NOT leave that position blank. Second, ''stdin'' doesn''t has an
EOF until you press Ctrl+d, thus you can''t exit.

<

Cong Wang说:
Cong Wang said:

>
qa ******* @ eyou.com 写道:

>我使用windows xp的操作系统,
和编译器是trubo c 3.0
当我输入数据时,以下程序不能退出。
这个程序会发生什么?
编译器有问题吗?
#include< stdio.h>
main(int argc,char * argv [])
{FILE * fp;
void filecopy(FILE *,FILE *) ;
if(argc == 1)
filecopy(stdin,stdout);

while(--argc> 0)
if((fp = fopen (* ++ argv," r"))== NULL){
printf(cat:不能打开%s \ n,* argv);
返回1;
} else {
filecopy(fp,stdout);
fclose(fp);
}
返回0;
}
void filecopy(FILE * ifp,FILE * ofp)
{int c;
while((c = getc(ifp))!= EOF)
putc(c,ofp) );
>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);
}



好​​吧,首先,如果你知道函数main是int。添加类型为

名称。不要将该位置留空。


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.


Second,''stdin在按Ctrl + d之前,没有

EOF,因此你不能退出。
Second, ''stdin'' doesn''t has an
EOF until you press Ctrl+d, thus you can''t exit.



错误。


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上面的域名(但显然放弃了www)

Wrong.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)



qa ******* @ eyou.com 写道:

qa*******@eyou.com wrote:

我使用windows xp的操作系统,

和编译器是trubo c 3.0

当我输入数据时,以下程序不能退出。

这个程序发生了什么?

编译器有问题吗?
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?



我不喜欢你的代码的格式化,但我看不到明显的

致命缺陷。 />

有了更多大括号(cos''我想看看我在做什么)和一些

整理缩进,它在我的系统上运行良好。


更好地解释你的问题可能会有所帮助 - 你的意思是

,如果你只是没有参数运行你的程序,你就不能退出
从它?如果是这样,你知道你需要在平台上输入什么吗?

表示stdin上的EOF?

I don''t like the formatting of your code, but I can''t see an obvious
fatal flaw.

With more braces (cos'' I wanted to see what I was doing) and some
tidied indentation, it worked fine on my system.

A better explanation of what your problem was may help - do you mean
that if you just ran your program with no arguments, you couldn''t exit
from it? If so, do you know what you need to type on your platform to
indicate EOF on stdin?


这篇关于我的学习有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆