c语言字符串空字符
初步结论:1.只有将字符数组初始化为字符串,空字符后面才会自动清为空字符;
2.若是后续赋值(或利用gets_s、%输入)为字符串,则只添加空字符,后续的仍为其他内容;
3.若利用for循环给字符数组逐个赋值,则需手动在末尾添加空字符。
测试代码如下:
(vs2015+win10)
# include <stdio.h>
# include <string.h>
int main(void)
{
char name[40];
scanf("%s", name);
printf("%c", name[20]);
return 0;
}
wall
请按任意键继续. . .
# include <stdio.h>
# include <string.h>
int main(void)
{
char name[40];
scanf("%s", name);
printf("%d", name[20]);
return 0;
}
dass
-52请按任意键继续.
# include <stdio.h>