-1

Im practicing with the toupper function but i can make this work, always crash at the point of the printf so i think arguments are bad, or so.

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main (void){

char pepito[10];

puts("\nTell me something: \n");
scanf("%9s", pepito);
puts("\a");
printf("Could be this?: %s", toupper(pepito[2]));

system("pause");    





}

1 Answers1

1

I'm not sure why you only call toupper() on the third char (and then tries to print the third char as a string - %s is not %c), I suspect that is actually your question - so your program should actually be using index 1 (indices start at 0),

int main (int argc, char *argv[]) {
  int i = 0;
  char pepito[10];

  puts ("\nTell me something: \n");
  scanf ("%9s", pepito);
  /* Capitalize the third letter. */
  pepito[1] = toupper (pepito[1]);
  /* print the capitalized pepito */
  printf ("Could be this?: %s\n", pepito);
}

Running it produces

$ ./a.out 

Tell me something: 

random
Could be this?: rAndom
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249