【发布时间】:2015-01-07 00:19:56
【问题描述】:
我正在使用 Visual Studio 2012。
我需要写一个句子,然后检查该句子中有多少单词以大写字母开头(A,G,Z,U ...)-好的,我做到了,现在我需要写去掉以大写字母开头的单词
例如:“嗨,请帮我解决这个问题”,我需要我的程序说: " 5 个单词以大写字母开头,这些单词是:Hi Please Help With QUESTION "
这是我已经做过的(计算以大写字母开头的单词):
#include<stdio.h>
#include<string.h>
#define lenght 20
int main(){
char sentence[lenght];
int i,n=0,num;
printf("\nWrite a sentence: ");
gets(sentence);
if(sentence[0]>='A' && sentence[0]<='Z'){
n++;
}
num=strlen(sentence);
for(i=0;i<num;i++){
if(!(sentence[i]>='A' && sentence[i]<='Z' || sentence[i]>='a' && sentence[i]<='z')){
if(sentence[i+1]>='A' && sentence[i+1]<='Z'){
n++;
}}}
printf("\nNum of words that start with uppercase letter is:%d \n",n);
return 0;
}
这可行,但我不知道如何写出以大写字母开头的单词,我尝试了 strcpy 但没用,我也尝试只用 printf 做,但也没有用。 请帮忙! P.S 谢谢大家的帮助!
【问题讨论】:
-
"... 以大写字母开头(A,G,Z,U...)" - 大写字母的例子?严重地?任何不知道大写字母是什么的人请举手:-)
标签: string visual-studio-2012 uppercase words sentence