Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 单链表中第一个没有';Don’不要给我数据_C - Fatal编程技术网

C 单链表中第一个没有';Don’不要给我数据

C 单链表中第一个没有';Don’不要给我数据,c,C,这是完整的代码:我希望有人能帮我解决这个问题 #include <assert.h> #include <stddef.h> #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdbool.h>

这是完整的代码:我希望有人能帮我解决这个问题

             #include <assert.h>
            #include <stddef.h>
            #include <stdio.h>
            #include <string.h>
            #include <ctype.h>
            #include <stdbool.h>
            #include <stdlib.h>
 

           
            struct word_count {
                char* word;
                int count;
                struct word_count* next;
            };
            
            /* Introduce a type name for the struct */
            typedef struct word_count WordCount;
            
            /* Global data structure tracking the words encountered */
            WordCount* word_counts = NULL;
            


            /* The maximum length of each word in a file */
            #define MAX_WORD_LEN 64
            void init_words(WordCount** wclist) {
                /* Initialize word count.  */
                wclist = NULL;
                //wclist = (WordCount*)malloc(sizeof(WordCount));
            }
此函数用于在列表不为空时将节点添加到列表的末尾

                void add_word(WordCount** wclist, char* word) {
                    WordCount* temp;
                    temp = (WordCount*)malloc(sizeof(WordCount));
                    if (temp == NULL) {
                        printf("error");
                        return;  
                    }
                    else {
                        temp->word = word; 
                        temp->count = 1;
                        temp->next = NULL;
                    }
            
                    if (*wclist == NULL)//the list is empty          
                        *wclist = temp;  //first node
                    else//this list is not empty
                    {
                            WordCount* p;
                            p = wclist; 
                            while ((p->next) != NULL) {
                
                                p = p->next;
                            }           
                            p->next = temp; //add new node to end of the list                
                   }    
                
                }
    
用于打印列表的函数:

            void printList(WordCount** wclist)
            {
                if(wclist==NULL)
                {
                    printf("empty");
                    return;
                }
                WordCount* wc = NULL;
                wc=wclist;
            
                while (wc != NULL)
                {
                    printf("[ %s | %d ]->", wc->word, wc->count);
                    wc = wc->next;
                }
            }
            
这是主要问题:

            int main()
            {
                init_words(&word_counts);
            
                char* strings[] = { "abc","def","aaa","bbb","zzz","aaa" };
                add_word(&word_counts, strings[0]);   
                add_word(&word_counts, strings[1]);
                add_word(&word_counts, strings[2]); 
                add_word(&word_counts, strings[3]);
                add_word(&word_counts, strings[4]);
                add_word(&word_counts, strings[5]);
                printList(&word_counts);
            
            }
            
例如,当我将单词插入列表时,第一个节点不会出现

            input:
            > "abc" "def" "aaa" "bbb" "zzz" "aaa" 
            
            the output:
            
            > [ X{δ | 1 ]->[ def | 1 ]->[ aaa | 1 ]

第一个错误:在
init_words
中,行
wclist=NULL
应为
*wclist=NULL
打印列表中
这是错误的
wc=wclist。编译器应该在那里给您一个警告,因为类型不兼容。不要忽视警告!在发布有关堆栈溢出的任何问题之前,请修复所有问题。它应该是
wc=*wclist非常感谢您的帮助
            input:
            > "abc" "def" "aaa" "bbb" "zzz" "aaa" 
            
            the output:
            
            > [ X{δ | 1 ]->[ def | 1 ]->[ aaa | 1 ]