Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
667 views
in Technique[技术] by (71.8m points)

Error "too few arguments to function call, at least argument 'format' must be specified" C programming

#include <cs50.h>

//declare functions

int add_two_ints(int a, int b);

int main(void)
{
    //ask the user for input
    
    printf("give an integer: ");
    int x = get_int();

    printf("give me another integer: ");
    int y = get_int();
    //call function

    int z = add_two_ints(x, y);
    

    printf("the result of %i plus %i is %i!
", x, y, z);


}

//function
int add_two_ints(int a, int b)
{
    int sum = a + b;
    return sum;
}

when i run the program i get the error too few arguments to function call, at least argument format must be specified

this is a simple function with only two arguments being pass since im new to c programming im trying to figure out where i made the mistake. whats is the correct way to write function ?

question from:https://stackoverflow.com/questions/66051125/error-too-few-arguments-to-function-call-at-least-argument-format-must-be-sp

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The get_int function included as part of CS50 expects a string for a prompt, which you're not passing. So instead of this:

printf("give an integer: ");
int x = get_int();

You want this:

int x = get_int("give an integer: ");

And similarly for reading y.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...