implicit declaration of function 'get_string'

13.1k Views Asked by At

I get the following error

cc     string.c   -o string
string.c:7:16: warning: implicit declaration of function 'get_string' is invalid in C99
      [-Wimplicit-function-declaration]
        string name = get_string();
                      ^
string.c:7:9: warning: incompatible integer to pointer conversion initializing 'string' (aka 'char *')
      with an expression of type 'int' [-Wint-conversion]
        string name = get_string();
               ^      ~~~~~~~~~~~~
2 warnings generated.
ld: can't write output file: string for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [string] Error 1

when I try to

make string

the code of string.c:

  1 #include <stdio.h>
  2 #include <cs50.h>
  3 
  4 int main(void)
  5 {
  6         printf("Name: ");
  7         string name = get_string();
  8         printf("hello, %s\n", name);
  9 
 10 }

The code is identical to the course on Week1.

Bare in mind that i have downloaded the cs50.h and installed it as per instructions from the CS50 library manual for OSX system.

1

There are 1 best solutions below

6
On

According to the cs50 manual, the function name is GetString() not get_string(). So, outdated implicit the function declaration kicks in (which is not valid since C99), resulting in compiler assuming get_string() returns an int. But since there's no definition for get_string() eventually the linking fails.

Change:

string name = get_string();

to:

string name = GetString();