#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{ char* key="844607587";
while(*key!=0){
printf("hello world,%c\n",*key);
key++;}
}
Run Code Online (Sandbox Code Playgroud)
为什么程序不能停在零位数?然后0是什么意思?那个没有''的人
您犯了一个简单的错误 - 您将字符串中的(最可能的ASCII)字符与数值0进行比较.更改:
while(*key!=0){
Run Code Online (Sandbox Code Playgroud)
至
while(*key!='0'){
Run Code Online (Sandbox Code Playgroud)
请注意,数值0是C字符串终止符的值,通常写为'\0',因此代码在到达字符串末尾时停止,而不是在它看到字符时停止'0'.