gpt4 book ai didi

c - 连续运行应用程序

转载 作者:太空狗 更新时间:2023-10-29 15:44:56 26 4
gpt4 key购买 nike

持续运行应用程序以使其在触底后不退出的最聪明的方法是什么?相反,它再次从 main 的顶部开始,并且仅在收到命令时退出。 (这是在 C 中)

最佳答案

你应该总是有一些干净退出的方法。我建议将代码移到另一个返回标志以表明是否退出的函数。

int main(int argc, char*argv[])
{

// param parsing, init code

while (DoStuff());

// cleanup code
return 0;
}

int DoStuff(void)
{
// code that you would have had in main

if (we_should_exit)
return 0;

return 1;
}

关于c - 连续运行应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/593273/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com