我正在编写的代码,从用户输入的整数,并创建一个链表,然后打印出列表。整数应该放在列表的前面。从C键盘输入链接列表
我需要一点帮助我不知道如何让打印出的数字。
这里是我的代码:
Node.h
#include <stdio.h>
#include <stdlib.h>
#ifndef _nodes
#define _nodes
typedef struct node_s {
int d;
struct node_s *next;
} node1;
node1 list(int d);
node1 addbegin(int d, node1 *head);
node1 print(node1 *head);
#endif
node.c
#include "node.h"
#include <stdio.h>
node1 *list_nodes(int d){
node1 *node;
node=(node1*)malloc(sizeof(node1));
node->d=d;
node->next=NULL;
return(node);
}
node1 init(node1 *head){
head->next=NULL;
}
node1 addbegin_nodes(node1 *head, int d){
node1 *newnode;
newnode=(node1*)malloc(sizeof(node1));
newnode=list_nodes(d);
head->next=newnode;
return(newnode);
}
node1 print_nodes(node1 *head){
node1 *temp;
temp=(node1*)malloc(sizeof(node1));
for(temp=head->next;
temp;
temp=temp->next)
printf("%d", temp->d);
return (d);
}
MAIN.C
#include <stdlib.h>
#include <stdio.h>
#include "node.h"
int main(int argc, char* argv[]) {
node1 *head;
node1 *start;
int num;
printf("Please enter integers: ");
while(scanf("%d", &num)!=EOF){
head=(node1*)malloc(sizeof(node1));
list(head);
int i=0;
for(i=0;i>=0;i--){
addbegin(head, num);
print(head);
}
printf("\n");
print(head);
}
return 0;
}
作业问题 – Almo
EOF是一个特殊字符。你是否退出循环? – BlackBear
是的,这是一个重要的问题,我一直在为它工作了5小时,自杀!所以我最终决定寻求帮助。 EOF是文件的结尾。 – Cka91405