简体   繁体   English

立即结束模拟C

[英]Ending simulation instantly C

To start off, I'm pretty new to the programming world. 首先,我是编程领域的新手。 I have thorougly searched for an answer to my question, but the search engines never give me what I want. 我一直在寻找问题的答案,但是搜索引擎从来没有给我想要的东西。

I am programming in C, using Code::Blocks. 我使用C :: Blocks在C中进行编程。 I want to know if I could add a line of code that would end the running program immediately when that statement is encountered during the simulation. 我想知道是否可以添加一行代码,以在模拟过程中遇到该语句时立即结束正在运行的程序。 I want this to happen even if the statement is not in the main function. 我希望即使该语句不在main函数中,也会发生这种情况。

For example, here is a very simple code with two functions (without the extra detail) to explain further. 例如,这是一个非常简单的代码,具有两个功能(没有多余的细节)以进一步说明。 Keep in mind that this code is meant solely to explain my question and is not used for practical reasons. 请记住,此代码仅用于解释我的问题,并非出于实际原因而使用。

int testc()
{
    for (c=0; c<=5; c++)
    {
        if (c == 2)
        {
        printf("Ending program");
        /*END RUN HERE*/
        }
    }
}

int main(void)
{
testc();
return 0;
}

I'm sorry if the answer is somewhere on the internet. 如果答案在互联网上某个地方,我感到抱歉。 I have been searching for the past hour and I can't seem to find a solution to my problem. 我一直在搜索过去一个小时,但似乎找不到解决我问题的方法。

是的,使用stdlib.hexit( int )函数,其中参数是进程的退出代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM