fork download
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <errno.h>
  4. #include <string.h>
  5. /** /
  6. int Chop_if(char str[],char ch){
  7. int i = 0;
  8. for (i = 0; str[i] != '\0'; i++);
  9. if (i > 0){
  10. if(str[i - 1] == ch) str[i - 1] = '\0';
  11. }
  12. else return -1;
  13. return 0;
  14. }
  15. /**/
  16. int StringToUpper(char str[]){//inplace modify.
  17. int i = 0;
  18. for (i = 0; str[i] != '\0'; i++) str[i] = toupper(str[i]);
  19. return 0;
  20. }
  21. /*
  22. int PrintValue(char str[]){
  23. int i = 0;
  24. for (i = 0; str[i] != '\0'; i++)printf("%d ",str[i]);
  25. return 0;
  26. }
  27. */
  28.  
  29. int main(){
  30.  
  31. static const int Len = 4;
  32. char buff[Len];
  33. #if 1 //can process both for problem.
  34. while (1){
  35. if (fgets(buff, Len, stdin) == NULL && errno != EINVAL) break;
  36. //Chop_if(buff,'\n');
  37. //Chop_if(buff,26);//value of eof at char value.but eof can get int value.
  38. StringToUpper(buff);
  39. printf("%s", buff);
  40. //PrintValue(buff);
  41. }
  42. #else
  43. int ch = EOF;
  44. while ((ch = getchar()) != EOF){//よく考えたら、stdinが詰まってるのでブロッキングしません!
  45. ch = toupper(ch);
  46. putc(ch, stdout);
  47. fflush(stdout);//>>192が正解!
  48. }
  49. #endif
  50. return 0;
  51. }
Success #stdin #stdout 0s 2296KB
stdin
Hello World!!!
stdout
HELLO WORLD!!!