C语言代码:统计字符串中非括号字符的个数
#include <stdio.h>\n#include <string.h>\n\nint main() {\n char str[100];\n int count = 0;\n \n printf("Enter a string: ");\n fgets(str, sizeof(str), stdin);\n str[strcspn(str, "\n")] = '\0'; // Remove the newline character\n \n for (int i = 0; i < strlen(str); i++) {\n if (str[i] != '(' && str[i] != ')') {\n count++;\n }\n }\n \n printf("Number of characters that are not '(' or ')' is %d\n", count);\n \n return 0;\n}

原文地址: http://www.cveoy.top/t/topic/p3LY 著作权归作者所有。请勿转载和采集!