#include <stdio.h>
#include <string.h>
main() {
int i = 0, j = 0;
char ch[] = { "chicken is good" };
char str[100];
while ((str[i++] = ch[j++]) != '\0') {
if (i == strlen(str))
break;
}
printf("%s", str);
}
我想串"chicken is good"
从ch
使用while
循环复制到str
。但是,当我打印str
输出显示"chi"
。它只打印部分字符串。我的病情是错的吗?你能解释这个C程序中的输出吗?
我使用Dev C++作为我的IDE,我的编译器的版本是gcc 4.9.2。而且我也是编程新手。
删除'如果(我== strlen的(STR)) break' – BLUEPIXY
我得到了它@BLUEPIXY – kryptokinght