exit 和exit(1) 有什么不同啊。。。

huaxiangsl 2008-05-18 11:38:46
exit 和exit(0) 还有 exit(1) 有什么不同啊。。。

还有个问题。。。

x=getchar(); 不是要接收回车才结束的吗。。 怎么我里面有没按回车就完了啊。。
...全文
157 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
snailman 2008-05-19
  • 打赏
  • 举报
回复
exit(0) == exit(EXIT_SUCCESS)
exit(1) == exit(EXIT_FAILURE)

看看英文单词!
dtor 2008-05-19
  • 打赏
  • 举报
回复
飞雪正解
九桔猫 2008-05-19
  • 打赏
  • 举报
回复
全让飞雪给说了。
独孤过儿 2008-05-19
  • 打赏
  • 举报
回复

#include <stdlib.h>

void exit(int status);

DESCRIPTION
The exit() function causes normal process termination and the value of
status & 0377 is returned to the parent (see wait(2)).

All functions registered with atexit() and on_exit() are called, in the
reverse order of their registration. (It is possible for one of these
functions to use atexit() or on_exit() to register an additional function
to be executed during exit processing; the new registration is added to
the front of the list of functions that remain to be called.)

All open streams are flushed and closed. Files created by tmpfile() are
removed.

The C standard specifies two constants, EXIT_SUCCESS and EXIT_FAILURE,
that may be passed to exit() to indicate successful or unsuccessful ter-
mination, respectively.

RETURN VALUE
The exit() function does not return.

CONFORMING TO
SVr4, 4.3BSD, POSIX.1-2001.

getchar()那个问题是因为你在本次读入之前没有清空缓冲区,缓冲区内有别的垃圾数据,你将这些垃圾数据读入进来了,而你真正想

输入的数据却没进来,在getchar()前面显示的清空一下缓冲区就好了:fflush( stdin );
maimang09 2008-05-19
  • 打赏
  • 举报
回复
getchar()每一次只能接受一个字符!
mymtom 2008-05-18
  • 打赏
  • 举报
回复
[Quote=引用楼主 huaxiangsl 的帖子:]

还有个问题。。。

x=getchar(); 不是要接收回车才结束的吗。。 怎么我里面有没按回车就完了啊。。
[/Quote]

这个与终端模式有关,
就Unix来说
在行模式需要回车,在RAW模式下不需要回车。
可以通过stty来设置。
baihacker 2008-05-18
  • 打赏
  • 举报
回复
exit是一个函数名
exit(0)表示退出程序,返回值为0
exit(1)表示退出程序,返回值为1

一个有动作的函数,执行成功用0返回,非0表示执行错误。

但在判断函数中,一般用非0表示要判断的事物存在,而用0表示不存在。

这些只是C开发中的习惯。

x=getchar();
输入缓冲区中有剩余字符,所以最好在这句前面加上fflush(stdin);以清空那些字符

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧