So I just created my own toupper
(to capitalize a single character) and strupr
(to capitalize a string). But it doesn't work. So, here is the code.
#include <stdio.h>
int toupper(const int character) {
if (character >= 97 && character <= 122)
return (character - 32);
return character;
}
char *strupr(const char *string) {
char *result;
for (int a = 0; a < strlen(string); a++) {
*(result + a) = toupper(*(string + a));
}
return result;
}
int main() {
char myString[6] = "Hello";
printf("myString (Before): \"%s\"\n", myString);
printf("myString (After): \"%s\"\n", strupr(myString));
return 0;
}
And here is the output:
myString (Before): "Hello"
It just printed out the first line, after that the program stopped. So I need help fixing my code.