C 无法将分配中的节点转换为节点
我已经尝试了所有的方法,第59行的标题有这个错误 有一个.dat文件,我必须从.dat中排序并在.exe中打印 编译时,它表示无法转换。可能是什么 我只包含了有问题的函数和主代码C 无法将分配中的节点转换为节点,c,C,我已经尝试了所有的方法,第59行的标题有这个错误 有一个.dat文件,我必须从.dat中排序并在.exe中打印 编译时,它表示无法转换。可能是什么 我只包含了有问题的函数和主代码 #include <stdio.h> #include <stdlib.h> typedef struct node { int value; struct node * next; } node_t; struct node push(node_t * head, int
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int value;
struct node * next;
} node_t;
struct node push(node_t * head, int val)
{
node_t * current = head;
while (current->next != NULL)
{
current = current->next;
}
current->next = (struct node *)malloc(sizeof(node_t));
current->next->value = val;
current->next->next = NULL;
return current;
}
int main() {
node_t * list = (struct node *)malloc(sizeof(node_t));
FILE* file = fopen ("kol1.dat", "r");
int i = 0;
do
{
fscanf (file, "%d", &i);
list = push(list, i);
list = sort_list(list);
print_list(list);
}while (!feof (file));
fclose (file);
return 0;
}
#包括
#包括
类型定义结构节点{
int值;
结构节点*下一步;
}节点t;
结构节点推送(节点头,int val)
{
节点_t*电流=头部;
while(当前->下一步!=NULL)
{
当前=当前->下一步;
}
当前->下一步=(结构节点*)malloc(sizeof(node_t));
当前->下一步->值=val;
当前->下一步->下一步=空;
回流;
}
int main(){
node_t*list=(结构节点*)malloc(sizeof(node_t));
FILE*FILE=fopen(“kol1.dat”,“r”);
int i=0;
做
{
fscanf(文件“%d”和&i);
列表=推送(列表,i);
列表=排序列表(列表);
打印列表(列表);
}而(!feof(file));
fclose(文件);
返回0;
}
当前的类型是struct节点*
,但是您的推送功能返回的是结构节点
如此变化
struct node push(node_t * head, int val)
到
应该做这个工作。< /P>这里没有第59行。C不是C++不是C!选择一种语言。欢迎使用堆栈溢出。所以
list
是一个指针<代码>推送
返回结构。决定你在哪一边,但是你不应该像C++那样编程。使用C并删除不推荐的强制转换。编译并运行后,它就可以工作了,非常感谢!
struct node *push(node_t * head, int val)