<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Forum Pasja Informatyki - Najnowsze z tagiem cykliczna</title>
<link>https://forum.pasja-informatyki.pl/tag/cykliczna</link>
<description>Powered by Question2Answer</description>
<item>
<title>Lista cykliczna - problem przy dodawaniu elementów.</title>
<link>https://forum.pasja-informatyki.pl/141534/lista-cykliczna-problem-przy-dodawaniu-elementow</link>
<description>

&lt;p&gt;Witam.&lt;/p&gt;



&lt;p&gt;Piszę grę quiz. Napotkałem problem, który objawia się tym, że przy tworzeniu więcej niż jednego elementu listy, następują błędne przypisania danych. Przy jednym (pierwszym) elemencie wszystko jest w porządku. Poniżej podaję kod.&amp;nbsp;&lt;/p&gt;



&lt;p&gt;Pozdrawiam&lt;/p&gt;



&lt;pre class=&quot;brush:cpp;&quot;&gt;

struct question
{
    char question [250];
    char answer1 [50];
    char answer2 [50];
    char answer3 [50];
    char answer4 [50];
    char correct_answer [2];
    int id;
    struct question *next;
};

struct question *load_questions (struct question *list_pointer, char question [250], char answer1 [50], char answer2 [50], char answer3 [50], char answer4 [50], char correct [2], int id)
{
        struct question *new_node = (struct question *) malloc (sizeof(struct question));
        if (new_node){
            if (list_pointer == NULL){
                    new_node-&amp;gt;next = new_node;
            }else{
                new_node-&amp;gt;next = list_pointer-&amp;gt;next;
                list_pointer-&amp;gt;next = new_node;
            }

            strcpy (new_node-&amp;gt;question, question);
            strcpy (new_node-&amp;gt;answer1, answer1);
            strcpy (new_node-&amp;gt;answer2, answer2);
            strcpy (new_node-&amp;gt;answer3, answer3);
            strcpy (new_node-&amp;gt;answer4, answer4);
            strcpy (new_node-&amp;gt;correct_answer, correct);
            new_node-&amp;gt;id = id;
        }
        return new_node;
}





int main()
{
    char nick [11] = {0};
    int tmp;
    //----------WPROWADZANIE GRACZY -------------------------------------
    puts (&quot;Ilu graczy chcesz wprowadzic?&quot;);
    scanf (&quot;%d&quot;, &amp;amp;tmp);
    int i;
    struct player *players_pointer = NULL;
    for(i=0; i&amp;lt;tmp; i++){
        printf (&quot;Wprowadz nick gracza %d: &quot;, i);
        scanf(&quot;%s&quot;, nick);
        players_pointer = add_players (players_pointer, nick, i);
    }
    players_pointer = find_player (players_pointer, 0);
    //-----------------------------------------------------
    FILE *questions;
    struct question *questions_pointer = NULL;
    if ((questions = fopen (&quot;pytania.txt&quot;, &quot;r&quot;))){

                char question_tmp [250] = {'\0'};
                char answer1_tmp [50]   =   {'\0'};
                char answer2_tmp [50]   =  {'\0'};
                char answer3_tmp [50]   =  {'\0'};
                char answer4_tmp [50]   =  {'\0'};
                char correct_tmp [2]    =   {'\0'};

                for (i=0; i&amp;lt;2; i++){
                fgets( question_tmp, 250 , questions );
                fgets( answer1_tmp, 50 , questions );
                fgets( answer2_tmp, 50 , questions );
                fgets( answer3_tmp, 50 , questions );
                fgets( answer4_tmp, 50 , questions );
                fgets( correct_tmp, 2 , questions );

                questions_pointer = load_questions(questions_pointer, question_tmp, answer1_tmp, answer2_tmp, answer3_tmp, answer4_tmp, correct_tmp, i );


            }
    }
    questions_pointer = find_question(questions_pointer, 0);
    printf(&quot;%s&quot;, questions_pointer-&amp;gt;question);
    printf(&quot;%s&quot;, questions_pointer-&amp;gt;next-&amp;gt;question);


    return 0;
}
&lt;/pre&gt;



&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>
<category>C i C++</category>
<guid isPermaLink="true">https://forum.pasja-informatyki.pl/141534/lista-cykliczna-problem-przy-dodawaniu-elementow</guid>
<pubDate>Mon, 16 May 2016 13:51:18 +0000</pubDate>
</item>
</channel>
</rss>