警告1
警告说明:
警告 C6054 可能没有为字符串“s”添加字符串零终止符。
原因:
解决方案: 可以在创建数组时直接初始化。
原始:char s[30];
修改后:char s[30] = { 0 };
错误1
错误说明:
错误 C4996 ‘scanf’: This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
原因:scanf_s()更加安全,“scanf()在读取字符串时不检查边界,可能会造成内存泄露”
解决方案:scanf()改为scanf_s()。
原始:scanf("%s", s) == 1;
修改后:scanf_s("%s", s) == 1;
警告3
警告说明:
警告 C6064 缺少“scanf_s”的整型参数(对应于转换说明符“2”)。
警告 C4473 “scanf_s”: 没有为格式字符串传递足够的参数。
解决方案:在读取时,设置读取字符长度。
原始:scanf_s("%s", s) == 1
修改后:scanf_s("%s", s, 30) == 1
#include<stdio.h> #include<string.h> #include<ctype.h> const char* rev = "A 3 HIL JM O 2TUVWXY51SE Z 8 "; const char* msg[] = { "not a palindrome","a regular palindrome","a mirrored string","a mirrored palindrome" }; char r(char ch) {if (isalpha(ch)) {return rev[ch - 'A'];}return rev[ch - '0' + 25]; } int main() {char s[30] = { 0 };while (scanf_s("%s", s,30) == 1) {int len = strlen(s);int p = 1, m = 1;for (int i = 0; i < (len + 1) / 2; i++) {if (s[i] != s[len - 1 - i]) {p = 0;//不是回文串}if (r(s[i]) != s[len - 1 - i]) {m = 0;//不是镜像串}}printf("%s -- is %s.nn", s, msg[m * 2 + p]);}return 0; }
12345678910111213141516171819202122232425262728