I'm just beginning in C and I'm having a hard time with a segmentation fault in my code(which is pretty simple btw). The goal of the exercice is to capitalize each letter in a string. Could someone please help me out ?
here is the assignment: "Write a function that puts every letter of every word in it in uppercase" (we've got to do it manually without using other libraries methods).
here is the error message: "[1] 14328 segmentation fault (core dumped) ./a.out"
#include <stdio.h>
#include <unistd.h>
char *my_strupcase(char *str) {
int index = 0;
for (index = 0; str[index] != '\0'; index++) {
if ((str[index] >= 'a' && str[index] <= 'z') || (str[index] >= 'A' && str[index] <= 'Z')) {
str[index] = (str[index] - 32);
printf("%c \n", str[index]);
}
}
return str;
}
int main() {
my_strupcase("salut");
return (0);
}