i'm practicing strings now and what i try to do in this program is print something like: hello world into HellO WorlD as an output.
My code is the following one:
#include <stdio.h>
#include <string.h>
void convertir(char cadena[200]){
  int length = strlen(cadena);
  int i;
    printf("%c", cadena[0]-32); // Prints letter in caps
    for(i=1;i<length-1;i++){
      if(cadena[i] == ' '){ // Search if there is space
        printf("%c", cadena[i-1]-32);
        i=i+1; // Adds vaule on i with accumulator to make caps the letter after the space
        printf(" %c", cadena[i]-32); // prints letter in caps after space
      } else {
      printf("%c", cadena[i]); // prints everything in the string
      }
    }
    printf("%c", cadena[length-1]-32);
}
int main(int argc, char const *argv[]) {
  char cadena[200];
  printf("Introduce un texto: ");
  gets(cadena);
  convertir(cadena);
  return 0;
}
What the code compiled returns me after typing hello world is: HelloO WorlD, i'm trying to replace that o in HelloO but i'm getting confused... 
Any help is appreciated.
Thank you.
 
     
     
    