C 程序中的未知错误

C 程序中的未知错误,c,debugging,gcc,compiler-errors,linked-list,C,Debugging,Gcc,Compiler Errors,Linked List,我是C语言的新手,有Java背景,调试这些函数时遇到了麻烦。基本上,这个想法是他们将被传递一个单词,为链表创建一个节点,然后将新节点插入到链表中进行排序。我不明白代码中的错误是什么,我很难找到修复它们的方法。如果有人能在这方面帮助我走上正确的道路,我将非常感谢你的帮助!提前谢谢大家!请在下面找到我的函数的代码 #include <stdio.h> #include <string.h> //Node record struct node { char data; str

我是C语言的新手,有Java背景,调试这些函数时遇到了麻烦。基本上,这个想法是他们将被传递一个单词,为链表创建一个节点,然后将新节点插入到链表中进行排序。我不明白代码中的错误是什么,我很难找到修复它们的方法。如果有人能在这方面帮助我走上正确的道路,我将非常感谢你的帮助!提前谢谢大家!请在下面找到我的函数的代码

#include  <stdio.h>
#include <string.h>
//Node record
struct node {
char data;
struct node* next;
}; 



//insertion sorting (will sort as inserted)
void insert_dictionary_order(struct node** head_ref, char word)
{ 
   struct node* temp; 
   struct node* new_node; 
       new_node->data = word; 
       
   //If new insert is before head, put current head next, and set head to new node
   if (*head_ref == NULL || strcmp((*head_ref)->data, new_node->data) > 0)  //if new_node comes before this 
   {
       new_node->next=*head_ref; 
       *head_ref = new_node;
   } 
   else
   { 
       //find the node before insertion point 
       temp = *head_ref; 
       while(current->next != NULL && current->next->data < new_node->data) 
       { 
            current = current->next;
       } 
       new_node->next = next; 
       current->next = new_node;
   }
    
}



//function to print list by being passed head
void print_list(struct node *head) 
{ 
    Struct node *temp = head; 
    while(temp != NULL) 
    { 
        printf("%s\n", temp->data); 
        temp = temp->next;
    }
}


#包括
#包括
//节点记录
结构节点{
字符数据;
结构节点*下一步;
}; 
//插入排序(将按插入排序)
void insert\u dictionary\u order(结构节点**head\u ref,字符词)
{ 
结构节点*temp;
结构节点*新节点;
新建_节点->数据=字;
//若新插入在头之前,则将当前头放在下一个,并将头设置为新节点
if(*head_ref==NULL | | strcmp((*head_ref)->数据,new_node->data)>0)//如果new_node在此之前
{
新建节点->下一步=*头部\u参考;
*head\u ref=新节点;
} 
其他的
{ 
//在插入点之前查找节点
温度=*水头参考;
while(当前->下一步!=NULL&¤t->下一步->数据<新建节点->数据)
{ 
当前=当前->下一步;
} 
新建节点->下一步=下一步;
当前->下一步=新节点;
}
}
//通过传递头打印列表的函数
无效打印列表(结构节点*头)
{ 
结构节点*温度=头部;
while(temp!=NULL)
{ 
printf(“%s\n”,临时->数据);
温度=温度->下一步;
}
}
以下是我收到的错误:

17899186/source.c: In function ‘insert_dictionary_order’:
17899186/source.c:21:36: warning: passing argument 1 of ‘strcmp’ makes pointer from integer without a cast [-Wint-conversion]
    if (*head_ref == NULL || strcmp((*head_ref)->data, new_node->data) > 0)  //if new_node comes before this
                                    ^
In file included from 17899186/source.c:4:0:
/usr/include/string.h:136:12: note: expected ‘const char *’ but argument is of type ‘char’
 extern int strcmp (const char *__s1, const char *__s2)
            ^~~~~~
17899186/source.c:21:55: warning: passing argument 2 of ‘strcmp’ makes pointer from integer without a cast [-Wint-conversion]
    if (*head_ref == NULL || strcmp((*head_ref)->data, new_node->data) > 0)  //if new_node comes before this
                                                       ^~~~~~~~
In file included from 17899186/source.c:4:0:
/usr/include/string.h:136:12: note: expected ‘const char *’ but argument is of type ‘char’
 extern int strcmp (const char *__s1, const char *__s2)
            ^~~~~~
17899186/source.c:30:14: error: ‘current’ undeclared (first use in this function)
        while(current->next != NULL && current->next->data < new_node->data)
              ^~~~~~~
17899186/source.c:30:14: note: each undeclared identifier is reported only once for each function it appears in
17899186/source.c:34:25: error: ‘next’ undeclared (first use in this function)
        new_node->next = next;
                         ^~~~
17899186/source.c:16:17: warning: variable ‘temp’ set but not used [-Wunused-but-set-variable]
    struct node* temp;
                 ^~~~
17899186/source.c: In function ‘print_list’:
17899186/source.c:45:5: error: unknown type name ‘Struct’; did you mean ‘struct’?
     Struct node *temp = head;
     ^~~~~~
     struct
17899186/source.c:45:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
     Struct node *temp = head;
                 ^
17899186/source.c:46:11: error: ‘temp’ undeclared (first use in this function); did you mean ‘bcmp’?
     while(temp != NULL)
           ^~~~
           bcmp
17899186/source.c:在函数“insert\u dictionary\u order”中:
17899186/source.c:21:36:警告:传递'strcmp'的参数1将从整数生成指针,而不进行强制转换[-Wint转换]
if(*head_ref==NULL | | strcmp((*head_ref)->数据,new_node->data)>0)//如果new_node在此之前
^
在17899186/source.c:4:0中包含的文件中:
/usr/include/string.h:136:12:注意:应为“const char*”,但参数的类型为“char”
外部内部strcmp(常量字符*\uuuu s1,常量字符*\uuuu s2)
^~~~~~
17899186/source.c:21:55:警告:传递'strcmp'的参数2将从整数生成指针,而不进行强制转换[-Wint转换]
if(*head_ref==NULL | | strcmp((*head_ref)->数据,new_node->data)>0)//如果new_node在此之前
^~~~~~~~
在17899186/source.c:4:0中包含的文件中:
/usr/include/string.h:136:12:注意:应为“const char*”,但参数的类型为“char”
外部内部strcmp(常量字符*\uuuu s1,常量字符*\uuuu s2)
^~~~~~
17899186/source.c:30:14:错误:“当前”未声明(此函数首次使用)
while(当前->下一步!=NULL&¤t->下一步->数据<新建节点->数据)
^~~~~~~
17899186/source.c:30:14:注意:每个未声明的标识符对于其出现的每个函数只报告一次
17899186/source.c:34:25:错误:“下一步”未声明(此函数首次使用)
新建节点->下一步=下一步;
^~~~
17899186/source.c:16:17:警告:变量“temp”已设置但未使用[-Wunused但已设置变量]
结构节点*temp;
^~~~
17899186/source.c:在函数“打印列表”中:
17899186/source.c:45:5:错误:未知类型名“Struct”;你是说“结构”吗?
结构节点*温度=头部;
^~~~~~
结构
17899186/source.c:45:17:错误:应为“=”,“,”,“;”,”“*”标记前的asm”或“\uuuuuu属性\uuuuuuuu”
结构节点*温度=头部;
^
17899186/source.c:46:11:错误:“temp”未声明(此函数首次使用);你是说“bcmp”吗?
while(temp!=NULL)
^~~~
bcmp

好的,让我们来看看您收到的错误和警告:

  • 警告:传递'strcmp'的参数1会从整数生成指针,而无需强制转换[-Wint转换]

    警告:传递'strcmp'的参数2会从整数生成指针,而无需强制转换[-Wint转换]

    这些警告表示,
    strcmp
    需要一个指针,但您已向它传递了一个整数。即使这是一个警告,而不是一个错误(在我看来,这应该是一个错误),但在继续之前,您一定要解决它

  • 注意:应为“const char*”,但参数的类型为“char”

    这显示了
    strcmp
    的预期和提供的参数类型。您传递了一个
    char
    变量(
    (*head\u ref)->data
    new\u node->data
    ),但是
    strcmp
    需要
    const char*
    ,一个指向字符的指针(在
    strcmp
    的情况下基本上是一个字符串)

  • 错误:“当前”未声明(首次在此函数中使用)

    错误:“下一步”未声明(此函数首次使用)

    您没有在此函数中声明
    current
    next

  • 警告:变量'temp'已设置但未使用[-Wunused但已设置变量]结构节点*temp

    变量
    temp
    分配了一个值,但没有使用。这基本上是报告未使用的变量,您可以忽略此警告

  • 错误:未知类型名称“Struct”;你是说“struct”吗?

    错误是不言自明的,甚至可以提供解决方案。C区分大小写

  • 错误:应为“=”、“、”、“;”、”“*”标记之前的asm”或“\uuuuuu属性”

    错误:“temp”未声明(首次在此函数中使用);你是说“bcmp”吗?

    由于上一个错误而引发了这些错误。一旦你修正了打字错误
    Struct
    ->
    Struct
    ,这些应该会消失