How can I make a function in C that just returns the value of the string passed to it, for instance in the example given in main(), I would like to "normalize" the string "wACkY!" to just "Wacky!". I have managed to do this with a void function that directly modifies the string at its memory location, but what I want to do is not modify the string itself, but just return a modified version of it.
How can I do this?
printf("%s\n", normalize(string));
My normalize function
char *normalize(char *a) {
printf("%s\n", a);
int i = 0;
a[i] = toupper(a[i]);
for (i = 1; a[i] != '\0'; ++i) {
a[i] = tolower(a[i]);
}
return a;
}
In main()
char *string = "wACkY!";
printf("%s\n", string);
printf("%s\n", normalize(string));