#include <stdio.h>

#include <string.h>

#include <stdlib.h>


#define MAX_STR 10000000

#define MAX_PAT 3000


char str[MAX_STR];

char pat[MAX_PAT];

int size_str = 0;

int size_pat = 0;


void print(FILE*, int*);


int main(void) {

FILE* fp_str = fopen("string.txt", "r");

FILE* fp_pat = fopen("pattern.txt", "r");

FILE* fp_res = fopen("result_naive.txt", "w");


if (!fp_str) {

printf("The string file does not exist.\n");

return 0;

}

if (!fp_pat) {

printf("The Pattern file does not exist.\n");

return 0;

}

fgets(str, MAX_STR, fp_str);

fgets(pat, MAX_PAT, fp_pat);


size_str = strlen(str);

size_pat = strlen(pat);

int i = 0, j = 0;

int index = 0;

int* result = (int*)malloc(sizeof(int));

*result = 0;


for (i = 0; i < size_str - size_pat + 1; i++) {

for (j = 0; j < size_pat; j++) {

if (str[i + j] != pat[j])

break;

}

if (j == size_pat) {

index++;

result = (int*)realloc(result, (index + 1) * sizeof(int));

result[0]++;

result[index] = i;

}

}


print(fp_res, result);


fclose(fp_str);

fclose(fp_pat);

fclose(fp_res);

free(result);


return 0;

}

void print(FILE* fp, int* result) {

if (fp) {

fprintf(fp, "%d\n", result[0]);

for (int i = 1; i <= result[0]; i++)

fprintf(fp, "%d ", result[i]);

}

fprintf(fp, "\n");

printf("Program complete. Result saved to result_naive.txt\n");

}


이렇게 naive 알고리즘 만들었는데
string.txt는 hello world my name is world.
pattern.txt는 world

이래서
result_naive.txt에는
2
6 23
이렇게 입력되야 합니다

근데 이게 비주얼 스튜디오에서는 정상적으로 입력이 되는데
cspro에서 컴파일하면

0

이렇게 0만 입력됩니다. 도대체 왜 이런겁니까...형님들 제발 도와주세요. 밤새 하고있는데 모르겠어요.
제발 도와주세요 ㅠㅠㅠㅠ