I want to capitalize the first letter of the string "hello stackoverflow". In my C program, this string is stored in a char pointer named str_to_capitalize.
I don't understand why the following code is flowless :
#include <stdio.h>
void main()
{
char *str_to_capitalize = "hello stackoverflow";
printf("Value pointed by str_to_capitalize : %c\n", *str_to_capitalize);
//output: Value pointed by str_to_capitalize : h
}
but this one throw a segfault :
#include <stdio.h>
void main()
{
char *str_to_capitalize = "hello stackoverflow";
// printf("Value pointed by str_to_capitalize : %c\n", *str_to_capitalize);
*str_to_capitalize -= 32; //segfault
}