我怎么能立即关闭在C程序? [英] How can I immediately close a program in C?

查看:75
本文介绍了我怎么能立即关闭在C程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个C code,其中我分析一些数据。我已经设置了程序来处理只有100的数据输入。它拥有超过100时,它给分段错误。我想创建一个方法,这样,当数超过100的用户将被警告,该程序将终止。我知道如何从主要通过简单地返回0做到这一点,但是我很喜欢5个功能从主客场调用,这是很难做到的,在这个功能即使是返回0将保持它的循环。

I am writing a C code, in which I am analyzing some data. I have set the program to handle only 100 data inputs. when it is having more than 100 it is giving segmentation fault. I want to create a way so that when the number is above 100 the user will be warned and the program will terminate. I know how to do it from main by simply return 0, however I am like 5 function calls away from main and it is difficult to do that even a return 0 in this function will keep it looping.

是否有终止整个程序而不在主遭受任何直接的方式?

Is there any immediate way to terminate the entire program without being in main?

推荐答案

标准函数退出是你在找什么:

The standard function exit is what you are looking for:

终止进程通常情况下,终止进程进行定期清理。

Terminates the process normally, performing the regular cleanup for terminating processes.

首先,通过调用atexit对注册的所有功能在其注册的相反的顺序被执行。然后,所有数据流被关闭,临时文件中删除,并最终控制被返回到主机环境

First, all functions registered by calls to atexit are executed in the reverse order of their registration. Then, all streams are closed and the temporary files deleted, and finally the control is returned to the host environment.

状态参数返回到主机环境。

The status argument is returned to the host environment.

但如果你固定段错误的错误会更好。

It would be better though if you fixed the segfault error.

这篇关于我怎么能立即关闭在C程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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