ctype.h存的是与字符相关的函数;
这些函数虽然不能处理整个字符串,但是可以处理字符串中的字符;ToUpper()函数,利⽤toupper()函数处理字符串中的每个字符,转换成⼤写;PunctCount()函数,利⽤ispunct()统计字符串中的标点符号个数;
使⽤strchr()处理fgets()读⼊字符串的换⾏符;这样处理没有把缓冲区的剩余字符清空,所以仅适合只有⼀条输⼊语句的情况。s_gets()适合处理多条输⼊语句的情况。
1 #include 6 void ToUpper(char *); 7 int PunctCount(const char *); 8 9 int main(void)10 { 11 char line[LIMIT];12 char * find;13 14 puts(\"Please enter a line:\");15 fgets(line,LIMIT,stdin);16 find = strchr(line, '\\n');17 if(find) 18 *find ='\\0';19 ToUpper(line);20 puts(line); 21 printf(\"That line has %d punctuation characters.\\n\",PunctCount(line));22 23 return 0;24 }25 26 void ToUpper(char * str)27 { 28 while(*str)29 { 30 *str =toupper(*str);31 str++;32 }33 }34 35 int PunctCount(const char * str)36 { 37 int ct =0;38 while(*str)39 { 40 if(ispunct(*str))41 ct++;42 str++;43 }44 45 return ct;46 } 因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- awee.cn 版权所有 湘ICP备2023022495号-5
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务