cs50 / libcs50

This is CS50's Library for C.
https://cs50.readthedocs.io/libraries/cs50/c/
GNU General Public License v3.0
1.74k stars 853 forks source link

pset 1 #216

Closed omoikhekpen closed 4 years ago

omoikhekpen commented 4 years ago

i have an issue with compiling this program

include

include

int main(void) { // ask for a number int h = 0; printf("Height: "); h = get_int();

while (h < 0 || h > 8)
{
    printf("The height must be a whole number between 0 and 8 . Try again: ");
    h = get_int();
}

// on each row
for (int i = 0; i < h; i++)
{
    // print leading spaces

    for (int s = 0; s < h - i - 1; s++)
    {
        printf(" ");
    }

    // print left-side hashtags
    for (int x = h - i - 1; x <= h; x++)
    {
        printf("#");

    }
    // print gap
    printf("  ");

    // print right-side hashtags
    for (int x = h - i - 1; x <= h; x++)
    {
            printf("#");
    }

    // move to new line
    printf("\n");
}
return 0;

}

it keeps giving me this error mario.c:9:17: error: too few arguments to function call, at least argument 'format' must be specified h = get_int();


/usr/include/cs50.h:82:1: note: 'get_int' declared here
int get_int(const char *format, ...) __attribute__((format(printf, 1, 2)));
^
mario.c:14:21: error: too few arguments to function call, at least argument
      'format' must be specified
        h = get_int();
            ~~~~~~~ ^
/usr/include/cs50.h:82:1: note: 'get_int' declared here
int get_int(const char *format, ...) __attribute__((format(printf, 1, 2)));
^
2 errors generated.
Rubix982 commented 4 years ago

Basically, what C is trying to tell you is that according to the function definition over here, int get_int(const char *format, ...) attribute((format(printf, 1, 2)));, it is expecting you to give it an argument that it calls format, so it's actually expecting you to give it a single argument so the function can work properly as expected.

The error you made is that you didn't give it any arguments at all, here h = get_int();. As you can see, the const char in the function definition exists, which basically means right now is that it wants a string from you, just like you give printf a string, so that the function can use that string to do something that it needs to.

This is not a CS50 issue, though. Please read about function definition and function prototypes in C if you still don't get it.

Other than that, maybe close this issue now?

kzidane commented 4 years ago

Please refer to https://man.cs50.io/#cs50.h or run man get_* (e.g., man get_int) for example usages.