C编程: how do I terminate the program after the user enters a sentinel value?

标签 c return sentinel

所以我首先#define SENTINEL -1

并且在某个函数中,我设置了一个if语句

void blahblah(blah)
{
   printf("Enter an integer (-1 to quit)");
   scanf("%d", &value);
   if (value == SENTINEL)
     return;
}

但出于某种原因,它没有像我希望的那样终止程序?

最佳答案

return 并不意味着退出,它只是意味着从函数返回....在你的代码中,if 语句是无用的,因为如果 if 语句为假,函数无论如何都会返回。

你可能想从 blahbalh 返回一个值来表示退出。

关于C编程: how do I terminate the program after the user enters a sentinel value?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14823031/

相关文章:

c++ - C++中的 Mongoose 服务器

c - __declspec(dllimport) 和外部 (OBS)

javascript - jquery 从返回的数组中生成单个变量

redis - sentinel - 防止特定的奴隶被提升

python - 为什么 python 引用中的绑定(bind)实例方法不相等?

c - 是否存在短裤大小实际大于 16 位的平台

c - 如何在c编程中从long转换为float时获得两位小数

java - 如何让方法返回多个对象?

php - MySQLi 查询仅返回一行

java - 使用哨兵控制循环不断请求 double 值的程序