Fro the files int.c and string.c, I copied the code from the lecture exactly, and was receiving errors, then modified the code according to suggestions online by adding #include <cs50.h>
and I'm still receiving multiple errors when I try and compile it using both clang
and make
For int.c my code is:
#include <stdio.h>
#include <cs50.h>
int main (void)
{
int i = get_int("Integer: ");
printf("hello, %i\n", i);
}
And the errors I get:
~/workspace/ $ make int
clang -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wshadow int.c -lcrypt -lcs50 -lm -o int
int.c:5:13: error: implicit declaration of function 'get_int' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
int i = get_int("Integer: ");
^
int.c:6:21: error: more '%' conversions than data arguments [-Werror,-Wformat]
printf("hello, %i\n");
~^
int.c:5:9: error: unused variable 'i' [-Werror,-Wunused-variable]
int i = get_int("Integer: ");
^
3 errors generated.
make: *** [int] Error 1
Similarly for the file string.c my code is:
#include <stdio.h>
#include <cs50.h>
int main(void)
{
string s = get_string("Name: ");
printf("hello, %s\n", s);
}
And the error I get:
~/workspace/ $ clang string.c
string.c:5:5: error: use of undeclared identifier 'string'; did you mean 'stdin'?
string s = get_string("Name: ");
^~~~~~
stdin
/usr/include/stdio.h:168:25: note: 'stdin' declared here
extern struct _IO_FILE *stdin; /* Standard input stream. */
^
string.c:5:11: error: expected ';' after expression
string s = get_string("Name: ");
^
;
string.c:5:12: error: use of undeclared identifier 's'
string s = get_string("Name: ");
^
string.c:5:16: warning: implicit declaration of function 'get_string' is invalid in C99 [-Wimplicit-function-declaration]
string s = get_string("Name: ");
^
string.c:6:27: error: use of undeclared identifier 's'
printf("hello, %s\n", s);
^
string.c:5:5: warning: expression result unused [-Wunused-value]
string s = get_string("Name: ");
^~~~~~
2 warnings and 4 errors generated.
Any help will be greatly appreciated! (: