if I compile with XCode at the height of strcat()
the following error is returned:
Thread 1: EXC_BAD_INSTRUCTION (code = EXC_I386_INVOP, subcode = 0x0)
while, if I compile from terminal (gcc -Wall program.c -o Out
):
Illegal instruction: 4
lung2
is the length ofs2
.MAX
equals30
and it is the array's maximum length.
Here is the code:
char s1[MAX] = { '\0' };
char s2[MAX] = { '\0' };
int flag = 0;
char *ptr;
unsigned long int lung1, lung2 = 0;
int verifica = 0;
j = 0;
...
while (j < lung1) {
ptr = strstr(s1, s2);
if (ptr) {
strncpy(ptr, "*", lung2);
strcat(s1, ptr + lung2);
flag = 1;
} else {
j++;
}
}