1

I'm a complete beginner who just commenced on the CS50 course through EDX. While tryin out the walkthrough lessons in the CS50 IDE (clou9), I'm getting the following warning

"TEST.C: In function ‘int main()’:
TEST.C:6:19: warning: deprecated conversion from string constant to ‘string {aka char*}’ [-Wwrite-strings]
     string name = "David";"

The script is exactly the same as shown in the walkthrough section video but still getting this warning. For ready reference, code pasted below. I feel it mustbe some setting in the IDE since no error comes up while David runs this code in the video. Pls help.

The script given below for ready reference.

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

int main(void)
{
    string name = "David";
    printf("hello, %s\n", name);
}
1

2 Answers 2

0

You need to be sure to save your source code before running make. I can see that you haven't, because the error message says "In function 'int main()' but your sample code says int main(void).

The code the compiler is using was probably saved before you added the cs50 library header as well, which is why you are seeing that error.

After saving the file, run make again and it should work. If it still doesn't, be sure you have run update50, then closed and reopened your terminal tab.

0

You used a capital C in as your file extension. TEST.C rather than TEST.c. Using capital C as the extension means make will use a c++ compiler to compile this, which is why you get a warning. C++ is a bit more strict when it comes to type conversion. In the cs50 library string is an alias for char * but the right hand side of your expression "David" is a string literal, and thus it has type const char *.

tl;dr: change your file extension to .c instead of .C

You must log in to answer this question.

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