C语言代码优化:如何判断句子是否以感叹号结尾
{/'title/':/'printf(///'请输入一句以感叹号结尾的英文句子: /////');//n scanf(///'%c///',&p);/',/'description/':/'There seems to be a mistake in your code. The variable 'p' should be declared as a character array or string to store the input sentence. Here's the corrected code://n//nc//n#include <stdio.h>//n//nint main() {//n char sentence[100];//n //n printf(///'请输入一句以感叹号结尾的英文句子: /////');//n scanf(///'%[//^//n]s///', sentence);//n//n // Check if the sentence ends with an exclamation mark//n if (sentence[strlen(sentence) - 1] == '!') {//n printf(///'输入的句子正确!//n///');//n } else {//n printf(///'输入的句子不以感叹号结尾!//n///');//n }//n//n return 0;//n}//n//n//nThis code prompts the user to enter a sentence and then checks if the sentence ends with an exclamation mark. The result is printed accordingly./',/'keywords/':/'C语言, 代码优化, scanf, 字符串, 感叹号, 判断, 结尾/',/'content/':/'There seems to be a mistake in your code. The variable 'p' should be declared as a character array or string to store the input sentence. Here's the corrected code://n//nc//n#include <stdio.h>//n//nint main() {//n char sentence[100];//n //n printf(///'请输入一句以感叹号结尾的英文句子: /////');//n scanf(///'%[//^//n]s///', sentence);//n//n // Check if the sentence ends with an exclamation mark//n if (sentence[strlen(sentence) - 1] == '!') {//n printf(///'输入的句子正确!//n///');//n } else {//n printf(///'输入的句子不以感叹号结尾!//n///');//n }//n//n return 0;//n}//n//n//nThis code prompts the user to enter a sentence and then checks if the sentence ends with an exclamation mark. The result is printed accordingly./
原文地址: https://www.cveoy.top/t/topic/pD74 著作权归作者所有。请勿转载和采集!