strcat()在使用gcc的xcode中有问题

如果我在strcat()的高度使用XCode进行编译,则会返回以下错误:

Thread 1: EXC_BAD_INSTRUCTION (code = EXC_I386_INVOP,subcode = 0x0)

同时,如果我从终端(gcc -Wall program.c -o Out)进行编译:

Illegal instruction: 4   
  • lung2s2的长度。
  • MAX等于30,它是数组的最大长度。

代码如下:

    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++;
        }
    }
cry1018 回答:strcat()在使用gcc的xcode中有问题

该代码用星号s2替换了s1*的每次出现。

在某些平台上,如果源和目标重叠,则strcat的行为是不确定的,因为ptr指向s1,所以是这种情况。

本文链接:https://www.f2er.com/3128563.html

大家都在问