fork download
  1. /*Write a program to take a string input. Change it to sentence case.*/
  2. #include <stdio.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5.  
  6. int main() {
  7. char str[200];
  8. fgets(str, sizeof(str), stdin);
  9.  
  10. int i;
  11.  
  12. // convert entire string to lowercase first
  13. for (i = 0; str[i] != '\0'; i++)
  14. str[i] = tolower(str[i]);
  15.  
  16. // convert first non-space character to uppercase
  17. for (i = 0; str[i] != '\0'; i++) {
  18. if (str[i] != ' ') {
  19. str[i] = toupper(str[i]);
  20. break;
  21. }
  22. }
  23.  
  24. printf("%s", str);
  25. return 0;
  26. }
  27.  
  28.  
Success #stdin #stdout 0.01s 5276KB
stdin
hELLO hOw aRe yOu?
stdout
Hello how are you?