I have a function that I want to be able to use to find out if a string is in a string.
It compiles fine but then I get a Segmentation fault.
On GDB it says: Program received signal SIGSEGV, Segmentation fault.
0x08048539 in in ()
Code:
int in(char string[], char finder[]){
int i = 0;
int j = 0;
int r = 0;
int flag = 0;
while (string[i] != '\0') {
if (flag==0){ // If a part of finder has not yet been found in string
if (string[i]==finder[0]){ // check if it is the first letter of finder is this string
flag=1;
}
} else { // The letter has been found
if (finder[j]!='\0'){
j++;
if (finder[j]==string[i]){
r=1;
} else {
r=0;
}
}
}
i++;
}
return r;
}
On GDB it says: Program received signal SIGSEGV, Segmentation fault.
0x08048539 in in ()
Comment