- #1
iquicck
- 3
- 0
- Homework Statement
- C language,Linked List
- Relevant Equations
- Linked List
I have a problem there,I want to Users decide a,b,c,d,e numbers.
if I write
if ı do like that ,it has not any problem but its not effective,Program always asking number a,b,c etc.
My wish is program directly get all number in one time.
I tried this code;
But Program gave " too many arguments for format" error and giving wrong solution. How can ı fix this code?
Orjinal code:
if I write
C:
printf("enter numbers:");
scanf("%d",&a);
printf("enter numbers:");
scanf("%d",&b);...
My wish is program directly get all number in one time.
I tried this code;
C:
printf("enter numbers:");
scanf("%d",&a,&b,&c,&d,&e);
Orjinal code:
C:
#include <stdio.h>
#include <stdlib.h>
// A linked list node
struct Node
{
int data;
struct Node *next;
};void push(struct Node** head_ref, int new_data)
{
struct Node* new_node = (struct Node*) malloc(sizeof(struct Node)); new_node->data = new_data; new_node->next = (*head_ref); (*head_ref) = new_node;
}
void insertAfter(struct Node* prev_node, int new_data)
{
if (prev_node == NULL)
{
printf("the given previous node cannot be NULL");
return;
} struct Node* new_node =(struct Node*) malloc(sizeof(struct Node)); new_node->data = new_data; new_node->next = prev_node->next; prev_node->next = new_node;
}void append(struct Node** head_ref, int new_data)
{
struct Node* new_node = (struct Node*) malloc(sizeof(struct Node));
struct Node *last = *head_ref; new_node->data = new_data; new_node->next = NULL; if (*head_ref == NULL)
{
*head_ref = new_node;
return;
} while (last->next != NULL)
last = last->next;
last->next = new_node;
return;
}void printList(struct Node *node)
{
while (node != NULL)
{
printf(" %d ", node->data);
node = node->next;
}
}int main()
{
int a,b,c,d,e;struct Node* head = NULL;
printf("enter numbers:");
scanf("%d",&a,&b,&c,&d,&e); // The Problem is Here!
append(&head,a);
push(&head, b);push(&head, c);
;
append(&head, d);insertAfter(head->next, e);
printf("\n Created Linked List: ");
printList(head);
return 0;
}
Last edited: