C language "too many arguments for format" error

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 replies · 11K views
iquicck
Messages
3
Reaction score
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
C:
printf("enter numbers:");

scanf("%d",&a);

printf("enter numbers:");

scanf("%d",&b);...
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;
C:
printf("enter numbers:");

scanf("%d",&a,&b,&c,&d,&e);
But Program gave " too many arguments for format" error and giving wrong solution. How can ı fix this code?

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:
on Phys.org
The format specifier has to have one specification for each argument, e.g.,
C:
scanf ("%d%d", &a, &b);
 
  • Like
Likes   Reactions: iquicck