c - Converting string from lowercase to uppercase seg fault -
this question has answer here:
i trying convert string has been passed function lowercase uppercase. keep getting seg fault, , cannot determine why.
void uppercase(char* input) { int str_size = strlen(input); char *string = input; (int = 0; < str_size; i++) { string[i] += -32; printf("%c", string[i]); } return; }
function calling function uppercase:
#include <stdio.h> #include <string.h> int main(void) { uppercase("max"); return(0); }
as @dasblinkenlight said, cannot modify string literal.
try instead:
int main(void) { char str[4] = "max"; uppercase(str); return(0); }
or can malloc string , pass in.
Comments
Post a Comment