13

when you #include <cs50.h> the compiler looks for cs50.h in a standard list of system directories (e.g., /usr/include/). on the other hand, when you #include "cs50.h" the compiler looks for cs50.h first in the same directory as the directory of the current source code file, then a list of directories that is often referred to as quote directories, ...


10

The #include pre-processor directive does not copy the code from libraries to your source code. It deals with header files (i.e., the ones that end with the .h extension). In the pre-processing phase, different preprocessor directives are resolved. For example, the #include preprocessor directive, copies the contents of a header file and places them where ...


7

Well, this is a really good question that I also( at a point of time) googled up and found this image, which is enough to explain everything So, you can see in this image that the code is first pre processed and saved as a filename.i file and then it's compiled where, its converted to an filename.s, so, you must be thinking that where's my answer to the ...


5

They do not work. You have to compile a new version for the second processor using a compiler specific to that processor.


4

stdio.h is a header file from the C Standard Libraries, and their implementations are in the libc.a file, due to his common and extended use, this file is automatically linked by the compiler as if the -lc argument was especified on the compiler command like this: clang hello hello.c -lc On the other hand, the cs50 library is and external library created ...


3

The C programming language has many versions. -std=c99 lets the compiler know that we're using the standard version C99 (released in 1999). See more: http://en.m.wikipedia.org/wiki/C99


2

I needed to add -lm to the libraries and remove all headers from the Makefile. # space-separated list of header files HDRS = dictionary.h # space-separated list of libraries, if any, # each of which should be prefixed with -l LIBS = -lm While I was working on my hash function, I found I needed to use <math.h> in order to use exponents, so it was ...


2

You are in the wrong directory, change the directory to where your file is stored i.e. Desktop here jharvard@appliance (~) : cd ~/Desktop jharvard@appliance (~) : make f2c jharvard@appliance (~) : ./f2c


2

What we're looking at here is an object file, that's object code written in "Executable and Linkable Format", being interpreted as ASCII. At least that's what I'd judge it, according to the first four bytes' being ^?ELF. So, yes, it is a piece of machine code, but, you're right, this is not really how the 'machine' sees it of course. It is binary, as all ...


2

The makefile can be confusing at times because a lot of the steps are left out for simplicity sakes, and implied by make using default behaviour. It might make a bit more sense if you manually replace the variables (OBJS and HDRS) with their "expanded" values, e.g.: # automatically generated list of object files # OBJS = $(SRCS:.c=.o) OBJS = speller.o ...


2

Actual compilers perform a lot of optimizations while compiling the code. Older compilers and processors treated n++ and n=n+1 in different ways, producing a faster code for the first expression using register access instead of memory access.


2

If I get what you're asking correctly, you're asking how source code files that use compiled libraries on a specific machine compile and run properly on a different machine even if the machine code of these libraries is different. The short answer is that source code (i.e., the code we write) is actually machine-independent, unlike machine code (the 0s and ...


2

If you do not want to use the Appliance, you will need to use a compiler instead, and you will need a way to run it. Wikipedia has a list of compilers. But if you don't use the Appliance you won't have the cs50.h library so it will be harder for you (if at all possible, since I didn't finish all the assignments myself). The Appliance uses a Ubuntu based OS ...


2

Actually, it's not really anything to do with the code you've typed in. Its the clang compiler complaining. The breakout.c program would also suffer the same fate if clang was not told to suppress the error in the Makefile definition file. For breakout it contains the following option: -Wno-unused-variable -W is the command line option relating to a ...


1

Simple. You need to be in the same directory as the source code file to run make. The screen shot shows that you're in the root directory. You need to switch to the directory containing the source code file. If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)


1

This never has anything to do with the contents of the .c file and always to do with the location or name of the file. It's a common error for new programmers. When you run the command make caesar, the compiler is going to attempt to create an executable file called caesar. It will look for a file called caesar.c in the current directory. Unfortunately, ...


1

The compiler trusts the programmer. Some code might result in a memory leak depending on how you use it. Like malloc. If you look at the code, you would not know whether it results in a memory leak. It definitely can. Then fopen. Uses malloc and can create a memory leak. Where would you "detect" a memory leak if you're not examining the whole code of an ...


1

If you are coding this in Visual Studio, you cannot use GetInt() to get an integer. This is because this function is only in the CS50 library. You may have included the proper header file on the top, but the file does not exist in the Visual Studio library files. scanf() is a possible alternative. You can use: scanf("%d",n); Instead of: n = GetInt();


1

Hmmm, two consecutive questions with roughly the same issue. After running check50 on almost every problem from pset1 to pset5, it only happened on a handful of programs. Also, it has stopped happening on some of them, and only appears to be on one or two still. I'm thinking there was some kind of system update in progress. My suggestion is to wait a ...


1

Explicitly linking of library is only needed if you are using a non-standard library in your program such as math.h and cs50.h. Standard libraries such as stdio.h, stdlib.h, string.h, ctype.h etc. are by default linked in the linking step in the compilation process. Hope this answers your question.


1

because, unlike the math library, the standard library is linked by default unless you tell the compiler that you don't want that to happen, which isn't usually what you need.


1

If you want to find a easier way, go for a compiler like devcpp which also compiles C code. Since the souce for SPL is available in the comments already shared above, you can compile them and get a lib as output. Since you're good with cygwin already, use the makefile file that surely would be coming with the SPL library and make sure the libspl.a file is ...


1

If you think you pc is limited, i strongly recomend you to consider installing the cs50 appliance as a second operating system, this way when you turn on your computer you can chose between windows and the appliance. Said that. Here is a list of tools i think will help you to complete the psets using windows. For the C language part of the course: ...


1

I can assume that you have broken or not set CFLAGS and LDLIBS environment variables. In the same folder try to create a file called makefile and place the next lines inside it: CC=clang CFLAGS=-ggdb3 -O0 -std=c99 -Wall -Werror LDLIBS=-lcs50 -lm Then just call make: make getname for ABC ;)


1

Pay attention to these lines in your Makefile: # space-separated list of libraries, if any, # each of which should be prefixed with -l LIBS = You should add math.h so make knows it needs to link it (as in -lm)


1

adding further , this version of C has many cool new features which every programmer uses presently , like - single line comments starting with // initialising varibales where they are implemented- old school C - int i; for (i=0; condition ; operation) C99 - for (int i=0; condition ; operation)


Only top voted, non community-wiki answers of a minimum length are eligible