Closed Senya247 closed 3 years ago
You have compiled the code with -o
. As a result, hello
will be an object.
When you print an object out, it displays the machine language, hence the "special characters".
I think you can try again and compile it using make
since you have the libcs50.
@Nightmare247, sure you didn't take any other steps (e.g., manually editing cs50.h
once installed)? I just did
$ docker run -it ubuntu:20.10
$ apt-get update
$ apt-get install -y clang curl sudo vim
$ curl -s https://packagecloud.io/install/repositories/cs50/repo/script.deb.sh | sudo bash
$ sudo apt-get install libcs50
$ vim test2.c # after which I added your code and saved
$ clang -lcs50 test2.c -o hello
and that indeed compiled and executed okay.
And what do you see if you execute cat /usr/include/cs50.h
?
@dmalan , nope I never edited the file, also, all other functions like get_int
and get_float
work fine and here's what I see when i do cat /usr/include/cs50.h
`/**
/**
/**
/**
/**
/**
/**
/**
/**
`
@Nightmare247 if you navigate to the folder where your source code file is and run the following commands, what is the output?
echo $0
apt-cache policy libcs50
cat ./test2.c
clang --version
clang ./test2.c -lcs50 -ohello
./hello
Those warnings are what is seen when clang -lcs50 -test2.c -o hello -Werror
. The problem recreates on my machine with that header include removed, using the original compile command. Using gdb shows that name
does get set to what is typed in. Or if aborted, that get_string
from libcs50.so.10 was called. Could there be a path problem, some older cs50.h is found first?
@kzidane here's the output of all the commands
It still outputs weird characters.
@jms41276 I thought at first that some older version was being used, so I reinstalled libcs50 with sudo apt remove libcs50 && sudo apt install libcs50
, but that didn't change anything, also, here;s the output of locate cs50.h
if it helps in any way
Sounds like you have multiple versions of cs50.h
? If you installed the library using apt
(or apt-get
), you should only have /usr/include/cs50.h
. Did you install the one at /usr/local/include/cs50.h
manually? If so, can you try removing it or moving it somewhere else temporarily and try again?
@kzidane Thank you so much! I moved /usr/local/include/cs50.h
somewhere else and now it finally works!
Here's my simple code-
I compile it with
clang -lcs50 test2.c -o hello
it generates no errors, but generates these warnings-test2.c:6:16: warning: implicit declaration of function 'get_string' is invalid in C99 [-Wimplicit-function-declaration] string s = get_string("Input: "); ^ test2.c:6:12: warning: incompatible integer to pointer conversion initializing 'string' (aka 'char *') with an expression of type 'int' [-Wint-conversion] string s = get_string("Input: "); ^ ~~~~~~~~~~~~~~~~~~~~~ 2 warnings generated.
then when i execute it with
./hello
, i get this weird prompt this peice of code works fine on the online cs50 ide, so something must be wrong on my computer. Here's my computer's info- I'd installed the library with$ curl -s https://packagecloud.io/install/repositories/cs50/repo/script.deb.sh | sudo bash $ sudo apt-get install libcs50
How do I fix this?