0

I am receiving the following error while compiling my code:

jharvard@appliance (~/Dropbox/pset2): make initials
clang -ggdb3 -O0 -std=c99 -Wall -Werror    initials.c  -lcs50 -lm -o initials
initials.c:7:12: error: unused variable 's' [-Werror,-Wunused-variable]
    string s = GetString();
           ^
1 error generated.
make: *** [initials] Error 1

Here is my code:

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

int main(void)
{
    printf("Please enter your full name: ");
    string s = GetString();

    return 0;

}

I have tried the programs that David writes in the shorts: string-0, string-1 and string-2 and they all work when I write them. I have run update50 and restarted my virtual machine as well as recreating the pset2 directory after rm files and rmdir directory. Any suggestions?

1

Clang is telling you exactly what is going wrong..."unused variable 's'". Your code gets input from the user and stores it in a string variable s, then does nothing with it. If you do something with s the error goes away.

| improve this answer | |
0

Exactly as @KernelRutgers said, you should use s in a way or another (e.g., print it out). However, this is just a warning that is treated as an error because you're passing the -Werror option to clang. You may not pass that option and ignore the warning and everything will work just fine. Try executing the command below instead of make initials

clang -std=c99 initials.c -lcs50 -lm -o initials

This is not recommended, but just for the sake of testing.

| improve this answer | |

You must log in to answer this question.

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