#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct book{
int booknum;
long long int ISBN;
char bookname[40];
char from[40];
char composer[10];
char have[50];
char can;
struct book * blink;
}Book;

typedef struct client{
int idnum;
char password[20];
char name[10];
char address[100];
char phonenum[20];
struct client * clink;
}Client;

Client * Clientarrange (){
Client * tmp = NULL, * head=NULL,*tmp2=NULL;
FILE * f= fopen("client.txt","r");
tmp = head = (Client *)malloc(sizeof(Client));
while(fscanf(f,"%d|%[^|]|%[^|]|%[^|]|%s\n",&tmp->idnum,tmp->password,tmp->name,tmp->address,tmp->phonenum)!=EOF){
tmp -> clink = (Client *)malloc(sizeof(Client));
tmp2=tmp;
tmp = tmp->clink;
}
tmp2->clink=NULL;
free(tmp);
fclose(f);
return head;
}

Book * Bookarrange (){
Book * tmp = NULL, * head=NULL,*tmp2=NULL;
FILE * f= fopen("book.txt","r");
tmp = head = (Book *)malloc(sizeof(Book));
while(fscanf(f,"%lld|%d|%[^|]|%[^|]|%[^|]|%[^|]|%c\n",&tmp->ISBN,&tmp->booknum,tmp->bookname,tmp->from,tmp->composer,tmp->have,&tmp->can)!=EOF){
tmp -> blink = (Book *)malloc(sizeof(Book));
tmp2=tmp;
tmp = tmp->blink;
}
tmp2->blink=NULL;
free(tmp);
fclose(f);
return head;
}


int main(){
Client * c;
Book * b;
c= Clientarrange();
printf("%d\n",c->idnum);
b=Bookarrange();
printf("%d\n",b->booknum);
return 0;
}


txt파일엔...........
9204020000001|1926001|도봉산|김강산|중앙도서관 2층 자연과학대|Y
9204020000002|1926002|도봉산|김강산|중앙도서관 2층 자연과학대|Y
9204020000003|1926003|도봉산|김강산|중앙도서관 2층 자연과학대|Y
9204020000004|1926004|수락산|김강산|중앙도서관 2층 자연과학대|Y
9204020000005|1926005|수락산|김강산|중앙도서관 2층 자연과학대|N
9204020000006|1926006|불암산|김강산|중앙도서관 2층 자연과학대|Y
9204020000007|1926007|불암산|김강산|중앙도서관 2층 자연과학대|Y
9204020000008|1926008|북한산|김강산|중앙도서관 2층 자연과학대|Y
9204020000009|1926009|북한산|김강산|중앙도서관 2층 자연과학대|Y
9204020000010|1926010|설악산|김강산|중앙도서관 2층 자연과학대|N
이런식으로!!! 정렬 되어 있는데!!!

clinentarrange 는 제대로 돌아가는데 ㅠㅠ 똑같이 만든 bookarrange는 안돌아가요 ㅠㅠㅠㅠㅠㅠ

bookarrange에서 세그멘테이션 오류 떠요 ㅠㅠㅠㅠㅠㅠㅠㅠ 디버깅 하면 tmp -> blink = (Book *)malloc(sizeof(Book)); 여기가 이상하다고하고..

txt 파일을 첨부터 다시 써보기도했지만...결국 안돌아간다는...

아님.....다르게 링크드리스트 짜서좀알ㄹㅕ주세요 ㅠㅠㅠㅠ