题目描述:点击打开链接
值得一提的是:需要把这个用来输出的字符串最后手动补上一个0, tmp[count]='\0';
解决方法:
#include <stdio.h>
#include <string.h>
// 1. read in one line into a string str_in[101],预处理对字母部分全部转化成大写字母。
// 2. 从str_in里面读出来,并且判断要不要输出首字母。出去THE,
int main(){
char str_in[101];
char *p;
int k;
char tmp[101];
int count;
while(gets(str_in)>0){
// Capitalization
for(k=0;k<strlen(str_in);k++){
if(str_in[k]<='z' && str_in[k]>='a'){
str_in[k] = str_in[k] - 'a' + 'A';
}
}
p = str_in;
while(*p){
count = 0;
// 跳过开始空格
while(*p == ' ' || *p == '-') p++;
while(*p != ' ' && *p != '-' && *p!='\0'){
tmp[count++] = *p;
p++;
}
tmp[count]='\0';
if(strcmp(tmp,"THE")==0 || strcmp(tmp,"OF")==0 || strcmp(tmp,"A")==0 || strcmp(tmp,"FOR")==0 || strcmp(tmp,"AND")==0){
// Do nothing.
}else {
printf("%c",tmp[0]);
}
if(*p == '\0') printf("\n");
}
}
return 0;
}