#include<stdio.h>
#include<conio.h>
#include <stdlib.h>
#include<string>
struct link_list {
char mail[50];
int counter;
struct link_list *next;
};
typedef struct link_list node;
void main()
{
FILE *fp ;
char string1[80];
node *head=NULL;
int count_length=0;
char *fname = "email.txt";
fp = fopen (fname, "r") ;
char line [ 128 ]; /* or other suitable maximum line size */
int count=0;
while (fgets (line, sizeof line, fp) != NULL) /* read a line */
{
count++;
if(head==NULL)
{
head=(node *)malloc(sizeof(node));
fscanf(fp,"%s",string1);
strcpy(head->mail,string1);
head->counter=count;
head->next=NULL;
}
else
{
node *tmp = (node *)malloc(sizeof (node));
fscanf(fp,"%s",string1);
strcpy(tmp->mail,string1);
tmp->next = head;
tmp->counter=count;
head = tmp;
}
}
fclose(fp); fp = fopen (fname, "r") ;
fclose(fp);
//printf("%d",count_length);
getch();
}
프로그램이 실행될 때 프로그램에 어설 션 오류가 발생합니다. 아무도 날 디버깅 도와 드릴까요?파일과 연결된 목록
[파일에서 데이터를 가져 오기 위해 링크드리스트 사용] 가능한 중복 (http://stackoverflow.com/questions/4842166/linked-list-usage-to-obtain-data-from-file) – sarnold
어떻게 다른가? 마지막 질문부터? –
그것은 .. 이전 질문 문맥이 다르기 때문에 새로운 질문을 만들었습니다. –