A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

本帖最后由 wanderingman 于 2015-2-3 12:08 编辑
  1. #include <ctype.h>                                                                                                                     
  2. #include <string.h>                                                                                                                    
  3. #include <stdio.h>                                                                                                                     
  4.                                                                                                                                          
  5.   int main()                                                                                                                             
  6.   {                                                                                                                                      
  7.           char m[100] ;                                                                                                                        
  8.           char *p = m;                                                                                                                        
  9.           char ch = 'Y';                                                                                                                       
  10.           while(ch == 'Y' || ch == 'y')  // while for input loop                                                                                                  
  11.           {                                                                                                                                    
  12.                   printf("Please enter a sentence:\n");                                                                                             
  13.                   fgets(m,100,stdin); // Get string from keyboard                                                                                    
  14.                   p = m ;                                                                        
  15.                   if (isalpha(*p) && islower(*p))   // Check if  the string is begin with a lower char                                            
  16.                   {                                                                              
  17.                           *p = *p -32 ;                // Convert to upper                              
  18.                                                                                     
  19.                   }                                                                              
  20.                   p++;                                                                           
  21.                                                                                     
  22.                   while(*p)    //Not NULL then loop                                               
  23.                   {                                                                              
  24.                           if (islower(*p)&&!isalpha( *(p-1))) //Check if *p is the first char of a word               
  25.                           {                                                                                          
  26.                                   (*p) -= 32 ;                                                                              
  27.                           }                                                                                          
  28.                           p++;                                                                              
  29.                   }                                                                                    
  30.                   fputs(m,stdout); // Print on the screen                                             
  31.                                                                                           
  32.                   printf("\nDo you want to continue to covert?(y|n):");                                
  33.                   ch = getchar();                                                                              
  34.                   getchar();                                                                                    
  35.           }                                                                                               
  36.                                                                                                    
  37.           return 0;                                                                                       
  38.   }                                                                                                                                      
  39.                                                      
  40.                                                    
复制代码

代码可以实现循环判断。欢迎拍砖!

2 个回复

倒序浏览
凑合吧。。。。
回复 使用道具 举报
太棒了!!!!!!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马