C6054警告:可能没有为字符串添加字符串零终止符
当用一个字符数组作为字符串的缓冲区时,在定义数组时一定要初始化为0.
否则会提示C6054警告.
1 #include <stdio.h> 2 #include <string.h> 3 #define MAX_LENGTH 10 4 5 int main(void) 6 { 7 char str[MAX_LENGTH] = { 0 }; 8 scanf_s("%s", str, MAX_LENGTH); 9 size_t len = strlen(str); 10 printf("str = [%s]\n", str); 11 printf("len = %u\n", len); 12 return 0; 13 }