本帖最后由 wanderingman 于 2015-2-3 12:08 编辑
- #include <ctype.h>
- #include <string.h>
- #include <stdio.h>
-
- int main()
- {
- char m[100] ;
- char *p = m;
- char ch = 'Y';
- while(ch == 'Y' || ch == 'y') // while for input loop
- {
- printf("Please enter a sentence:\n");
- fgets(m,100,stdin); // Get string from keyboard
- p = m ;
- if (isalpha(*p) && islower(*p)) // Check if the string is begin with a lower char
- {
- *p = *p -32 ; // Convert to upper
-
- }
- p++;
-
- while(*p) //Not NULL then loop
- {
- if (islower(*p)&&!isalpha( *(p-1))) //Check if *p is the first char of a word
- {
- (*p) -= 32 ;
- }
- p++;
- }
- fputs(m,stdout); // Print on the screen
-
- printf("\nDo you want to continue to covert?(y|n):");
- ch = getchar();
- getchar();
- }
-
- return 0;
- }
-
-
复制代码
代码可以实现循环判断。欢迎拍砖! |
|