원래 free로 메모리 풀어주라고 해서 풀어줬는데 이런 메세지가 떠요.



viewimage.php?id=3dafdf21f7d335ab67b1d1&no=24b0d769e1d32ca73dec84fa11d0283195504478ca9b7677dc322d30c9349b456bc3b617550c054ce48860111a4884e518a443c35363717e0508ab12024199411a47d6aa1496f2


참고로 시커먼 실행창에서는 원하는 내용은 다 나왔거든요?



이건 왜 뜨는 걸까요?



(수정) 코드 전체 올려봅니다.ㅎㅎ..;; 지송;;

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#pragma warning(disable:4996)


const char* read_ins(FILE* in) {

static char buf1[1] = { 0 };

int bufcount = 0;

static int readcount = 0;

char buf2 = { 0, };

int endcount = 0;

do {

if (buf1[0] == 10) ++readcount;

fseek(in, readcount, SEEK_SET);

fread(buf1, sizeof(char), 1, in);

if (buf1[0] != 10) {

buf2[bufcount] = buf1[0];

++bufcount;

}

++readcount;

if (buf1[0] == 10 || buf1[0] == 32) { endcount = 1; }


} while (endcount==0);

return buf2;

}


struct Student {

char name;

char sex;

char region;

char subject[16];

float score;

int height;

int weight;

};


int LAD(struct Student* s,const char* buf) {

FILE* fp = fopen(buf, "r");

int done = 0;

struct Student temp;

int i = 0, o = 0, p = 0;

do {

fscanf(fp, "%s %c %s %s %f %d %d", &s[i].name, &s[i].sex, &s[i].region, &s[i].subject, &s[i].score, &s[i].height, &s[i].weight);

done++;

i++;

} while (fscanf(fp, "%s %c %s %s %f %d %d", &s[i].name, &s[i].sex, &s[i].region, &s[i].subject, &s[i].score, &s[i].height, &s[i].weight) != -1);

fclose(fp);


for (o = 0; o < done - 1; o++) {


for (p = o + 1; p < done; p++) {

if (strcmp(s[o].name, s[p].name) > 0) {

temp = s[o];

s[o] = s[p];

s[p] = temp;

}

}

}

return done;

}


void PRT(struct Student* s,int done) {

for (int i = 0; i < done; i++) {

printf("%s %c %s %s %f %d %d ", s[i].name, s[i].sex, s[i].region, s[i].subject, s[i].score, s[i].height, s[i].weight);

}

}



int main(void) {

char CREATE="CREATE";

char SEARCH="SEARCH";

char LOAD="LOAD ";

char PRINT ="PRINT";

char INSERT ="INSERT";

char y;

char buf;

int done;

struct Student *students = malloc(sizeof(struct Student[100]));

printf("실행 하시겠습니까(Y):");

scanf("%c", &y);

if (y ==89 ||y== 121) {

FILE* in = fopen("input.txt", "r");


strcpy(buf, read_ins(in));

if (strcmp(buf, CREATE) == 0) {


printf("CREATE명령어를 실행합니다. ");

struct Student s[100];

students = &s[0];

memset(s, 0, sizeof(s));


};


strcpy(buf, read_ins(in));


if (strcmp(buf,LOAD) == 0) {

printf("LOAD명령어를 실행합니다. ");

strcpy(buf, read_ins(in));

done=LAD(students,buf);

};


strcpy(buf, read_ins(in));


if (strcmp(buf, PRINT) == 0) {

printf("PRINT명령어를 실행합니다. ");

PRT(students, done);

};

fclose(in);

}

else {

printf("다시 입력해주세요.");

}

free(students);

return 0;

}



근데 저거 free(students)빼면 잘 실행되는데 걍 빼줘야 하나요?



참고로 free(students) 빼면..



viewimage.php?id=3dafdf21f7d335ab67b1d1&no=24b0d769e1d32ca73dec84fa11d0283195504478ca9b7677dc322d30c9349b456bc3b617550c054ce48860111a48e989c03697059d5309bd9f1a90778ee7d52ea9829128c72b

이렇게 결과만 딱 깔끔하게 잘 나와여.. 어디 찾아보니까 저 중단점 트리거 했다는게 이미 해제된 메모리를 또 해제하려고 하면 나온다던데 전 해제해준 적이 없거든요?



왜 그럴까요?