I don't know what is the problem here when Ι write make hello

umerkhan951@ide50:~/workspace/new $ make hello
clang -ggdb3 -O0 -std=c99 -Wall -Werror    hello.c  -lcs50 -lm -o hello
hello.c:8:21: error: more '%' conversions than data arguments [-Werror,-Wformat]
    printf("Hello, %s\n");
hello.c:7:12: error: unused variable 's' [-Werror,-Wunused-variable]
    string s = GetString();
2 errors generated.
make: *** [hello] Error 1"

these errors occur.

When I use clang hello.c -lcs50.h

hello.c:8:21: warning: more '%' conversions than data arguments [-Wformat]
    printf("Hello, %s\n");
1 warning generated.
/usr/bin/ld: cannot find -lcs50.h
clang: error: linker command failed with exit code 1 (use -v to see invocation)

these errors occurs i don't know what to do please help!



int main(void)
    printf("state your name: \n");
    string s = GetString();
    printf("Hello, %s\n");

Your problem is that you don't use printf() correctly. Here is what you have:

printf("Hello, %s\n");

The %s part, tells printf() that in that spot is going to be a string variable, it's not the name of your variable. If you wanted to print an int in that spot you would use the %d specification.

So this is how you should use printf() (I will change the name of your variable to make it more clear)

string name = GetString();
printf("Hello, %s", name);

See the , after the string literal in printf(). After this , are coming the names of the variables you want to print, in the order they need to be printed. See another example:

string my_name = "Chris";
string your_name = GetString();
printf("Hello, %s. My name is %s", your_name, my_name);

I hope this clears things up for you.

If this answers your question please accept it by clicking the gray check-mark to the left, so that it becomes green. You can also vote it up by pressing the up arrow above the check-mark. And don't forget to keep coding!

  • Thank you very much :) – Umer Khan Sep 19 '15 at 14:03
  • If you may, please also accept the answer by clicking the gray checkmark! Thanks! :) – ChrisG Sep 19 '15 at 14:17
  • Done If you may answer one more question, now how do i multiply a constant (or variable) number to the input ?? – Umer Khan Sep 21 '15 at 7:49
  • I don't get what you mean exactly. – ChrisG Sep 21 '15 at 19:49

You must log in to answer this question.

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