I am having problems with the get_string function. This is the error I'm getting "error: initializer element is not a compile-time constant"

Viewed 30

I just started cs50 introduction to computer science and I can't seem to get past the "Hello" assignment because I keep getting an error and I have no idea what to do. Here is my code:

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

string name = get_string ("What is your name? ");
int main(void)
{
    printf("Hello, %s\n",  name);
}

'''

1 Answers

Okay...I figured it out...I just had to define the variable within the curly brackets. Like this:

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

int main(void)

{
    string name = get_string("What is your name? ");
    printf("Hello, %s\n",  name);
}
Related