So, for an assignment, I had to finish a code meant to capitalize a string.
What I tried was this:
void capitalize(char *str)
int i = 0;
if (str[i] >= 97 && str[i] <= 122)
str[i] = str[i] - 32;
void strCopy(char *str2, char *str1)
*str1 = *str2;
*str1 = '\0';
int main(int argc, char **argv)
char string1 = "This is a really long string!";
printf("The original string is \"%s\"\n", string1);
printf("The capitalized string is \"%s\"\n", string2);
However, when I tried running the code it returned:
The original string is "This is a really long string!"
The capitalized string is "This is a really long string!"
strcopy does not seem to be the issue, as it copies the
string1 correctly to
I don't understand why
capitalize is not working, as it seems like it should be going through letter by letter and changing it to uppercase, if the letter falls within the ascii code for a lowercase letter.
I would greatly appreciate someone helping to point out where the error is.
Thanks in advance!