#include <stdio.h>
#include <string.h>
void space_to_tab(char *string) {
char str [strlen(string)];
int size = 0;
while(string[size] != '\0'){
if(string[size] == ' ')
str[size] = '\t';
else
str[size] = string[size];
size++;
}
*string = *str;
}
int main() {
char *str = "aa b";
printf("%s\n", str);
space_to_tab(str);
printf("%s\n", str);
}
I just started with C programming and I want to switch the spaces in a string with tabs and I get the error "Segmentation fault (core dumped)". I belive the error is in "*string = *str;" but I dont know how to change the pointer of one string to the other.