Possible Duplicate:
Why does simple C code receive segmentation fault?
Hi,
check out the following code:
int main(int argc, char* argv[]){
char* a = "z.x.f.t.e.a";
char* b = ".";
updateStr(a,b);
return 0;
}
int updateStr(char str[], const char* delim) {
int i=0;
int wordsCounter = 0;
while (str[i] != '\0') {
if (contains(delim,str[i])) {
printf("CONTAINED %c\n",str[i]); //debug
str[i] = SEPERATOR;
wordsCounter++;
}
i++;
}
//REST OF THE CODE....
return wordsCounter;
}
updateStr replaces each '.' with ';' (SEPERATOR). However, the line str[i] = SEPERATOR; throws segmentation fault and i don't have a clue why. what is the reason and how can i fix it?
thanks everyone