#define STRING_SIZE 1024


typedef struct strlink{

        char str[STRING_SIZE];

        struct strlink * nextString;

        struct strlink * prevString;

}strLink;


strLink * head = NULL;

strLink * current = NULL;

strLink * prevPtr = NULL;

strLink * tail = NULL;


char buf[STRING_SIZE];

int strSize=0;

int strReference = 0;


void readCommandLines()

{

        head = (strLink *)malloc(STRING_SIZE+8);

        current = head;

        while(1){

                if(fgets(current->str, STRING_SIZE , stdin)==NULL)

                        break;

                current->str[strlen(current->str)-1]='\0';

                current->nextString = (strLink *)malloc(STRING_SIZE+8);

                prevPtr = current;

                current = current->nextString;

                current->prevString = prevPtr;

        }

        tail = current;

}

void printCommands(){

        for(current = tail; current !=NULL ; current = current->prevString)

        {

                printf("Command line : %s\n",current->str);

        }

}





입력값

aaa

bbb

ccc


희망 결과 :

Command line : ccc

Command line : bbb

Command line : aaa


실제결과

Command line :

Command line : ccc

세그멘테이션 오류


제가 링크 리스트랑 malloc 제대로 구현한거 맞음?

답좀 부탁 ㅠㅠ