I have included the cs50 library however, I am still getting an error.


#include <stdio.h>
#include <cs50.h>

int main(void)
    printf("hello, %s\n");

string name = get_string ("What is your name?\n");


~/pset1/hello/ $ make hello
clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow    hello.c  -lcrypt -lcs50 -lm -o hello
hello.c:6:27: error: use of undeclared identifier 'name'
    printf("hello, %s\n", name);
hello.c:9:15: error: initializer element is not a compile-time constant
string name = get_string("What is your name?\n");
/usr/include/cs50.h:109:25: note: expanded from macro 'get_string'
#define get_string(...) get_string(NULL, __VA_ARGS__)
2 errors generated.
<builtin>: recipe for target 'hello' failed
make: *** [hello] Error 1
~/pset1/hello/ $ ./hello
hello, world

2 Answers 2


You need to ask the user first for his/her name

string name = get_string();

And then prints his/her name

printf("hello, %s/n", name);
  • thank you so much it worked!
    – Niha Rika
    Jun 28, 2020 at 18:45
  • No problem.Be sure to tick the answer if I helped you. Jun 28, 2020 at 18:49

string name = get_string ("What is your name?\n");

This line needs to be inside the main function.
It also needs to be before printf("hello, %s\n", name); this line, since you can't use the name variable until after it exists.

You must log in to answer this question.

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