JonasJR
JonasJR

Reputation: 76

Missing argument? C-programming

I can't seem to find the faulty link in this piece of code:

#include "queue.h"

int pause(){
    return 1;
}

void add_to_queue(person p){

    if(full() != 1){

        printf ("\nAnge förnamn:");
        scanf ("%c", p.first_name);
        printf ("\nAnge efternamn:");
        scanf ("%c", p.sure_name);
        printf ("\nAnge person nummer:");
        scanf ("%c", p.pers_nbr);
        enqueue(p);
    }
    else{
        printf ("\nKön är full!");
    }
}

void show_menu(){
    printf ("\n**** Meny ****\n");
    printf ("1. Lägg till personer i kön\n");
    printf ("2. Ta bort personer ur kön\n");
    printf ("3. Skriv ut kön\n");
    printf ("4. Avsluta\n\n");
}

int get_selection(){
        int selection;
        do{
                printf ("Ange ett alternativ 1-4: ");
                scanf ("%d", &selection);

                if (selection >= 1 && selection >= 4){
                    printf ("\nFel");
                }

        }while (selection < 1 && selection < 4);

        return selection;
}

void run_selection(int selection){
        switch (selection){
            case 1 :add_to_queue();   <------- THIS IS WHERE THE PROBLEM IS!
                break;

            case 2 ://remove_from_queue();
                break;

            case 3 ://print_queue();
                break;

            case 4 : exit(0);
                break;

        default:
            printf( "Ogiltigt val! Tryck enter och välj ett alternativ mellan 1-4" );
            break;
    }
}

it gives me the error:

menu.c:49:10: error: too few arguments to function ‘add_to_queue’

but I can't figure out what argument it should be here? Tried the add_to_queue(p) and the add_to_queue(person p) and everything.... HELP!!!!

Upvotes: 0

Views: 1726

Answers (3)

erbdex
erbdex

Reputation: 1909

  1. Declare person p first.
  2. Use add_to_queue(p);
  3. i presume you've declared the person structure in the header you've included.

Upvotes: 0

Koldar
Koldar

Reputation: 1407

From the definition of add_to_queue

void add_to_queue(person p);

at the top of your code the function needs a variable of type "person". You should create one and pass to the function.

Upvotes: 1

haccks
haccks

Reputation: 106012

Your function definition of add_to_queue() includes a parameter of type person. You have to pass an argument of type person to add_to_queue() in return_selection function.
Or change

void add_to_queue(person p){...}  

to

void add_to_queue(void){...}

Upvotes: 1

Related Questions