I am attempting my own implementation of the toupper()
function in C; my function should work for strings of any length. I am not sure why my compiler is throwing a segmentation error when I attempt to change the contents of the string as seen below. Is there any way around this error? (I have tried using arrays as opposed to pointers, but to no avail.) Note: isLetter()
is a function I wrote that determines whether a character is an alphabetical character.
void toUpper(char *s){
while(*s != '\0'){
if(isLetter(*s)&&(*s> 90)){
*s += ('a' - 'A');
}
s++;
}
I call the function like this:
char *s = "Hello";
toUpper(s);