Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 21994

strcat() has a problem in xcode using gcc

$
0
0

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 of s2.
  • MAX equals 30 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++;
        }
    }

Viewing all articles
Browse latest Browse all 21994

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>