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. int StringToUpper(char str[]){//inplace modify.
  16. int i = 0;
  17. for (i = 0; str[i] != '\0'; i++) str[i] = toupper(str[i]);
  18. return 0;
  19. }
  20. /*
  21. int PrintValue(char str[]){
  22. int i = 0;
  23. for (i = 0; str[i] != '\0'; i++)printf("%d ",str[i]);
  24. return 0;
  25. }
  26. */
  27.  
  28. int main(){
  29.  
  30. char buff[1024];
  31.  
  32. while (1){
  33. if (fgets(buff, 1024, stdin) == NULL && errno != EINVAL) break;
  34. Chop_if(buff,'\n');
  35. Chop_if(buff,26);//value of eof at char value.but eof can get int value.
  36. Chop_if(buff,-1);//value of eof at command prompt.this is spooky value??
  37. StringToUpper(buff);
  38. printf("%s", buff);
  39. //PrintValue(buff);
  40. }
  41. /*int ch = EOF;
  42. while ((ch = getchar()) != EOF){
  43. ch = toupper(ch);
  44. putc(ch, stdout);
  45. }
  46. */
  47. return 0;
  48. }
Success #stdin #stdout 0s 2296KB
stdin
hello world!! ^z
stdout
HELLO WORLD!! ^Z