C Programming Error: 'collect2: error: ld returned 1 exit status' - Unresolved Variable 'j'
There is a compilation error in the code. It seems that the variable 'j' is not declared before being used in the inner loop. To fix this, we can declare 'j' as an integer before the loop:
#include<stdio.h>
#include<string.h>
int main()
{
char a[100], b[100];
gets(a);
gets(b);
char* p = NULL;
p = strstr(a, b);
if (p != NULL) {
for (int i = 0, j; i < strlen(a); i++) {
if (&a[i] == p) {
for (j = i + strlen(b); j < strlen(a); j++) {
a[i] = a[j];
i++;
}
break;
}
}
}
return 0;
}
原文地址: https://www.cveoy.top/t/topic/mCho 著作权归作者所有。请勿转载和采集!