I've written a function which I want to replace all the spaces in a string with '-'. I get a Segmentation Fault when I run it. However, using gdb with a break point set in the function and stepping through it, it works fine.
Thanks in advance!
int replace (char *cat);
char *s1 = "The cat sat ";
printf("The string before replacement is: \n");
int n = replace(s1);
printf("Number of replaced spaces: %d\n", n);
printf("The string after replacement is: \n");
int replace (char *cat)
int length = strlen(cat);
int r = 0;
for (i=0; i < length; i++)
printf("cat[%d]: %c\n", i, cat[i]);
if (cat[i] == ' ')
cat[i]='-'; // results in Seg Fault (set break point at beginning of line)