fork(2) download
  1. #include <stdio.h>
  2.  
  3. void capitalize(char *str)
  4. {
  5. for (int i = 0; str[i] != '\0'; ++i) { // Here we check for the end condition of a string.
  6. // ie. Has the Null termination been reached?
  7. if (str[i] >= 'a' && str[i] <= 'z') {
  8. str[i] = str[i] - ('a' - 'A');
  9. }
  10. }
  11. }
  12.  
  13. void strCopy(char *str2, char *str1)
  14. {
  15. while (*str2) {
  16. *str1 = *str2;
  17. str2++;
  18. str1++;
  19. }
  20. *str1 = '\0';
  21. }
  22.  
  23. int main(int argc, char **argv)
  24. {
  25. char string1[100] = "This is a really long string!";
  26. char string2[100];
  27. strCopy(string1,string2);
  28. capitalize(string2);
  29. printf("The original string is \"%s\"\n", string1);
  30. printf("The capitalized string is \"%s\"\n", string2);
  31. }
Success #stdin #stdout 0s 2156KB
stdin
Standard input is empty
stdout
The original string is "This is a really long string!"
The capitalized string is "THIS IS A REALLY LONG STRING!"