我想用 while 循环计算 C 中 char 数组的长度。
但如果我插入 otto
,它会返回 5
的长度。 4
不应该是正确答案吗?
char eingabe[255];
printf("geben Sie eine Zeile ein:");
fgets(eingabe, 255, stdin);
int i = 0;
while (eingabe[i] != '\0')
{
++i;
}
printf("Laenge: %d\n", i);
最佳答案
eingabe
很可能包含:
{ 'o', 't', 't', 'o', '\n', '\0', junk ... }
关于c - C中char数组的长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26931453/