gpt4 book ai didi

c - 为什么我会遇到 isdigit() 的段错误?

转载 作者:太空狗 更新时间:2023-10-29 16:09:12 26 4
gpt4 key购买 nike

场景 1:代码:

int main(){
int a = 12345678;

if(isdigit(a)){
printf("ok: foo\n");
}
else{
printf("false: bar\n");
}
printf("test\n");

return EXIT_SUCCESS;
}

输出:

Segmentation fault

场景 2:代码:

 ...
if(isdigit(a)){
//printf("ok: foo\n");
}
else{
//printf("false: bar\n");
}
printf("test\n");
...

输出:

test

现在是最后一个,代码:

...
int a = 1234567;
...

输出:

ok: foo
test

isdigit() 有什么问题?我不明白!

最佳答案

可能是因为编译器优化了代码中的 isdigit 函数调用。那就是它不运行它。

另请注意,isdigit 需要一个字符,而不是数字。 http://www.cplusplus.com/reference/clibrary/cctype/isdigit/

关于c - 为什么我会遇到 isdigit() 的段错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7165486/

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