why I do not define string s = getstring ();
?
hell.c
# include & lt; stdio.h & gt;
#include & lt; cs50.h & gt;
INT MAIN (Void)
{
Printf ("State Our Name:");
String S = getString ();
PrintF ("Hello,% S \ N", s);
}
CC Hell.c -o Hell
/ tmp / cchzxs2m.o: in function` Main ' Hell.c :(. Text + 0x16): undefined reference to `getstring ' Collect2: Error: LD Returned 1 Exit Status Make: *** [Hell] Error 1
1
Why don’t you use the scanf () method
for reading from the console?
int main (void) {
String Name;
Printf ("Enter your name");
Scanf ("% S", Name);
Printf ("Hi,% s \ n!", Name);
Return 0;
}
2, Authority 400%
need to be compiled and linked with the CS50.C file
CC -C Help.c -o Help.o
CC -C CS50.C -O CS50.C
CC -O Help Help.o CS50.O
3, Authority 200%
Because you have no such function getstring ().
Add for example above ..
String GetString (Void)
{
Return "Test";
}
4, Authority 100%
I can assume that you have selected or have not been configured by environment variables CFlags and LDLIBS . Try to create in the same folder file with the name makefile and place these lines:
CC = Clang
CFLAGS = -GGDB3 -O0 -STD = C99 -Wall -Werror
LDLIBS = -LCS50 -LM
After that, just call Make:
make hell
for abc;)
5
Because CS50 is a CS50 Harvard Course Library. And you have not installed. Run in their remote linux environment and it is picked up.
6
.h
file only declare list of functions,
To use their program, their code must be compiled by their code most likely in .c
with sink files (but it may be in .asm .Haskell ….lib .dll .so .a)
In the simplest case, you have a CS50.C file somewhere, which also needs to be compiled:
gcc -o ./hello[.exe] Hello.c CS50 / LIB / SRC / CS50.C
PS: description of the principle of using modules, separate compilation and use of the keyword static
well explained in Yevgeny Linsky’s course
7
Surrounded by CS50 on c9.io starting with 2016 This feature was renamed to:
get_string ()
Use it or find more recent video lectures.
8
Because you did not read normally starting tasks – there is so fat written the CT
Additional materials
reference.cs50.net/ – explanation of the functions of libraries used during training. In English.
http://computer.howstuffworks.com/c.htm p. 11 – 14 and 39
And so if you go into explanation of the libraries’ functions – and search for the String search – it will be a miracle, it turns out that you need to connect the library String.h – and it is not spelled out in CS50 – the guys did not do the crutch! Why the crutch to the library ready?