메모리 관련 질문있습니다;;;

mtg1의 이미지

#include
#include
#include
#include //getch

#define MAX 25000 //입력할 수 있는 인원수
#define DATA 100 //입력할 수 있는 최대 크기
#define MAXN 256//입력할 수 있는 버퍼 최대 크기
#define SWAP(x,y) { int t;t=x;x=y;y=t; }

int i=0;z=0, j;

int buffer;
int number[MAX];
int in1[MAXN], in2[MAXN],in3[MAXN], out[MAXN];
struct field{
short l;//전체 길이
short len;//필드2(이름) 길이
int num;//번호
char name[20];//사원이름?
float f;//평점
char s;//성별

};

void load(struct field fi[]){
FILE *fp1, *fp2;
char separators[]="|\n";
//struct field fi[MAX];
char data[100];
int k=0,l=0;//인원,필드,데이터
char *tok;

if((fp1=fopen("seq(4000).dat","rb"))==NULL){
printf("존재하지 않는 파일입니다.\n");
exit(1);
}
if((fp2=fopen("input.txt","wb"))==NULL){
printf("파일오류\n");
exit(1);
}
while(fgets(data,sizeof(data),fp1) != NULL ){
tok = strtok(data, separators);
buffer=atoi(tok);
...
}
j=z;
fclose(fp1);
fclose(fp2);
}

void inputb(){//바이너리 형식으로 저장한 input.txt읽기
FILE *fp1;
char data[10];
char separators[]=" \n";
int a=0;
char *tok;

if((fp1=fopen("input.txt","rb"))==NULL){
printf("input.txt파일이 생성되지 않았습니다.\n");
exit(1);
}

while( fgets(data,sizeof(data),fp1) != NULL ){
tok = strtok(data, separators);
number[a]=atoi(tok);
a++;
}
fclose(fp1);

}

void merge1(){//여기서는 temp작성'만'하고, test.
FILE *fp1, *fp2;//fp1은 temp, 2는 test
...

fclose(fp1);
fclose(fp2);
}

소스가 압박이긴 하지만;;

대충 이진파일에서 불러들인 후 3way-merge를 하는 코드입니다...만;

계속 실행을 하면 잘못된 메모리 참조라고 뜨면서 종료되버리네요;

밑에 main에서 load를 주석처리 하면 실행은 되지만, 금방 다른데서 에러뜨고;;

도와주세요..;
(소스 많으면 다 않올라오네요;;)

mtg1의 이미지

생각해보니 malloc으로 맨 위의 구조체를 MAX 만큼 저장을 하지 않은 상태에서 저걸 추가하면서
생긴 오류일까요;; 그러면 malloc 추가 하는 것좀;;

anster의 이미지

글쓰실때 위에 나와있는것과 같이 코드를 태그 형식으로 묶어 써주시면 훨씬 보기가 편해요..

복군의 이글루
anster.egloos.com

===================

복군의 이글루
http://anster.egloos.com

mtg1의 이미지

while(fgets(data,sizeof(data),fp1) != NULL ){
printf("+");
tok = strtok(data, separators);
fi[z].l=(short)atoi(tok);
printf("+");
tok = strtok(NULL, separators);
fi[z].num=atoi(tok);
printf("+");
+ 표시는 에러난 곳 찾으려고 넣었던 겁니다만;;
++ 두게 출력, 즉 여기서 에러가 나고 있습니다;;
설명좀;;

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.