Click here to Skip to main content
15,888,351 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionOutput characters into a file Pin
Francis Paran2-May-11 9:40
Francis Paran2-May-11 9:40 
AnswerRe: Output characters into a file Pin
Niklas L2-May-11 10:21
Niklas L2-May-11 10:21 
GeneralRe: Output characters into a file Pin
Francis Paran2-May-11 13:10
Francis Paran2-May-11 13:10 
Questionhow to make folder to file extension Pin
sarfaraznawaz2-May-11 2:43
sarfaraznawaz2-May-11 2:43 
AnswerRe: how to make folder to file extension Pin
David Crow2-May-11 2:59
David Crow2-May-11 2:59 
AnswerRe: how to make folder to file extension Pin
Niklas L2-May-11 5:23
Niklas L2-May-11 5:23 
AnswerRe: how to make folder to file extension Pin
Hans Dietrich2-May-11 6:02
mentorHans Dietrich2-May-11 6:02 
Questionimplementing multi linked list correctly_? Pin
quartaela1-May-11 23:52
quartaela1-May-11 23:52 
hi there i am working on a project and i am trying to implementing a multi linked list which nodes include more than one data and they are ordered diffrently by these keys(name,surname etc). i implemented the list and checked. so everything goes very well but after i realize that maybe i am not creating a multi linked list Smile | :) i know there must be more than one header node for a multi linked list and i added the nodes by name and first name correctly. so the only issue i am curious about. am i creating the multi linked list correctly or am i creating 2 different linked list.

this is the code which i pass the node as parameter to add functions;

 while ( !feof(myfile) ) {

        NODE* pnew_stu;

        if( !(pnew_stu = (NODE*) malloc(sizeof(NODE))) ) {

            printf("ERROR NOT ENOUGH MEMORY!!!\n");
            exit(100);
        }

        fscanf(myfile,"%s", &(pnew_stu->first_name) );
        fscanf(myfile,"%s", &(pnew_stu->last_name) );
        fscanf(myfile,"%s", &(pnew_stu->email_addr) );
        fscanf(myfile,"%d", &(pnew_stu->phone_num) );
        fscanf(myfile,"%s", &(pnew_stu->address) );
        fscanf(myfile,"%s", &(pnew_stu->city) );
        fscanf(myfile,"%d", &(pnew_stu->zipcode) );

        add_fn_Node(list,pnew_stu);
        add_ln_Node(list,pnew_stu);

}


and this is the functions i added the node by name and first name;

void add_fn_Node(LIST* list, NODE* pnew_stu) {

    NODE* temp = list->fn_head;

    if( !(temp = (NODE*) malloc(sizeof(NODE))) ) {

            printf("ERROR NOT ENOUGH MEMORY!!!\n");
            exit(100);
        }

    if( list->fn_head == NULL ) {

            pnew_stu->fn_next = list->fn_head;
            pnew_stu->fn_pre = list->fn_head;


            list->fn_head = pnew_stu;

            list->fn_count = 1;

            return;

        }

        else {

            temp = list->fn_head;

            if ( (strcmp( pnew_stu->first_name, temp->first_name )) <= 0 ) { // Adding to the beginning

                pnew_stu->fn_next = temp;
                pnew_stu->fn_pre = temp->fn_pre;
                temp->fn_pre = pnew_stu;

                list->fn_head = pnew_stu;

                list->fn_count++;

                return;

            }

            else {


                 while ( temp->fn_next != NULL ) { // Adding to the middle

                        if ( (strcmp( pnew_stu->first_name, temp->first_name ) <= 0 ) && (strcmp( pnew_stu->first_name, temp->fn_pre->first_name) > 0)) {

                        pnew_stu->fn_next = temp;
                        pnew_stu->fn_pre = temp->fn_pre;
                        temp->fn_pre->fn_next = pnew_stu;
                        temp->fn_pre = pnew_stu;

                        list->fn_count++;

                        return;
                    }

                        temp = temp->fn_next;

                    }

                if ( temp->fn_next == NULL ) { // Adding to the End

                    temp->fn_next = pnew_stu;
                    pnew_stu->fn_pre = temp;
                    pnew_stu->fn_next = NULL;

                    list->fn_tail = pnew_stu;

                    list->fn_count++;

                    return;

                }
            }

        }
}

void add_ln_Node(LIST* list, NODE* pnew_stu) {

    NODE* temp = list->ln_head;

    if( !(temp = (NODE*) malloc(sizeof(NODE))) ) {

            printf("ERROR NOT ENOUGH MEMORY!!!\n");
            exit(100);
        }

    if( list->ln_head == NULL ) {

            pnew_stu->ln_next = list->ln_head;
            pnew_stu->ln_pre = list->ln_head;


            list->ln_head = pnew_stu;

            list->ln_count = 1;

            return;

        }

        else {

            temp = list->ln_head;

            if ( (strcmp( pnew_stu->last_name, temp->last_name )) <= 0 ) { // Adding to the beginning

                pnew_stu->ln_next = temp;
                pnew_stu->ln_pre = temp->ln_pre;
                temp->ln_pre = pnew_stu;

                list->ln_head = pnew_stu;

                list->ln_count++;

                return;

            }

            else {


                 while ( temp->ln_next != NULL ) { // Adding to the middle

                        if ( (strcmp( pnew_stu->last_name, temp->last_name ) <= 0 ) && (strcmp( pnew_stu->last_name, temp->ln_pre->last_name) > 0)) {

                        pnew_stu->ln_next = temp;
                        pnew_stu->ln_pre = temp->ln_pre;
                        temp->ln_pre->ln_next = pnew_stu;
                        temp->ln_pre = pnew_stu;

                        list->ln_count++;

                        return;
                    }

                        temp = temp->ln_next;

                    }

                if ( temp->ln_next == NULL ) { // Adding to the End

                    temp->ln_next = pnew_stu;
                    pnew_stu->ln_pre = temp;
                    pnew_stu->ln_next = NULL;

                    list->ln_tail = pnew_stu;

                    list->ln_count++;

                    return;

                }
            }

        }
}

AnswerRe: implementing multi linked list correctly_? Pin
Stefan_Lang2-May-11 0:22
Stefan_Lang2-May-11 0:22 
GeneralRe: implementing multi linked list correctly_? Pin
quartaela2-May-11 0:28
quartaela2-May-11 0:28 
GeneralRe: implementing multi linked list correctly_? Pin
Stefan_Lang2-May-11 0:44
Stefan_Lang2-May-11 0:44 
GeneralRe: implementing multi linked list correctly_? Pin
quartaela2-May-11 0:56
quartaela2-May-11 0:56 
GeneralRe: implementing multi linked list correctly_? Pin
Stefan_Lang2-May-11 2:44
Stefan_Lang2-May-11 2:44 
GeneralRe: implementing multi linked list correctly_? Pin
quartaela2-May-11 4:06
quartaela2-May-11 4:06 
GeneralRe: implementing multi linked list correctly_? Pin
Stefan_Lang2-May-11 4:44
Stefan_Lang2-May-11 4:44 
GeneralRe: implementing multi linked list correctly_? Pin
quartaela2-May-11 4:59
quartaela2-May-11 4:59 
GeneralRe: implementing multi linked list correctly_? Pin
Stefan_Lang2-May-11 6:20
Stefan_Lang2-May-11 6:20 
GeneralRe: implementing multi linked list correctly_? Pin
quartaela2-May-11 7:38
quartaela2-May-11 7:38 
AnswerRe: implementing multi linked list correctly_? Pin
David Crow2-May-11 9:13
David Crow2-May-11 9:13 
GeneralRe: implementing multi linked list correctly_? Pin
quartaela2-May-11 9:37
quartaela2-May-11 9:37 
QuestionHow does Google Chrome Installer gets installed with UAC Prompt Pin
Raj Aryan 10011-May-11 22:29
Raj Aryan 10011-May-11 22:29 
AnswerRe: How does Google Chrome Installer gets installed with UAC Prompt Pin
Hans Dietrich1-May-11 22:53
mentorHans Dietrich1-May-11 22:53 
GeneralRe: How does Google Chrome Installer gets installed with UAC Prompt Pin
Raj Aryan 10011-May-11 23:00
Raj Aryan 10011-May-11 23:00 
AnswerRe: How does Google Chrome Installer gets installed with UAC Prompt Pin
Hans Dietrich1-May-11 23:06
mentorHans Dietrich1-May-11 23:06 
GeneralRe: How does Google Chrome Installer gets installed with UAC Prompt Pin
Raj Aryan 10011-May-11 23:13
Raj Aryan 10011-May-11 23:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.