0

I write this code (this is c programming):

#include <stdio.h>

int main(void)
{
    int i = get_int("Integer: ");
    printf("hello, %i\n");
}

error it gives:

~/workspace/ $ make int
clang -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wshadow    int.c  -lcrypt -lcs50 -lm -o int
int.c:5:13: error: implicit declaration of function 'get_int' is invalid in C99
      [-Werror,-Wimplicit-function-declaration]
    int i = get_int("Integer: ");
            ^
int.c:6:19: error: more '%' conversions than data arguments [-Werror,-Wformat]
    printf("hello%i\n");
                 ~^
int.c:5:9: error: unused variable 'i' [-Werror,-Wunused-variable]
    int i = get_int("Integer: ");
        ^
3 errors generated.
make: *** [int] Error 1
1

printf needs another argument to know what int it should print. You probably want

printf("hello, %i\n", i);

Also looks like you forgot to

#include <cs50.h>
2
  • I have the exact same issue, even after including both of your suggestions: ` #include <stdio.h> #include <cs50.h> int main (void) { int i = get_int("Integer: "); printf("hello, %i\n", i); }` – Xia Liu Jul 12 '18 at 14:13
  • Is the console output exactly the same? – Allan Clayton Jul 13 '18 at 0:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .