Hot answers tagged

6

crypt() is an encryption algorithm. It takes a plaintext string (a user password), and encrypts it, so that it can be stored in a file. char *crypt(const char *key, const char *salt) The key argument is the password to be encrypted, and salt is a two character string that 'tweaks' the algorithm's output. The output is a 13 character string. The first ...


5

The make utility actually calls the clang compiler with special options that can be set for a project. When I run make in the ide it actually runs the following: clang -fsanitize=integer -fsanitize=undefined -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wshadow temp.c -lcrypt -lcs50 -lm -o temp Most of that is unimportant to understand ...


3

It looks like you are trying to compile the program (make hello). To run the program the command is usually something like ./hello.


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


3

cc is typically an alias to gcc in Debian systems as far as I know. both gcc and clang are C compilers. a lot of source codes only compile correctly with CC value set to clang. well, for the purpose of this course both gcc/cc and clang can be used interchangeably. both are still different compilers though. I think the chance that some code compiles ...


2

It is , as Kareem stated, output file. If you type man clang in the terminal, you can find the following: -o file Write output to file. And pretty much everything about clang, including other what flags stand for.


2

Make sure the file named adder has the extension .c. Also make sure you're executing this command make adder NOT make adder.c


2

-Wall means to enable all compiler warnings. And -Werror means treat all warnings as errors. In other words, any possible warning that the compiler has determined will be shown to you if your code meets it, and it will be treated as a compile error that must be fixed.


2

First, .h files are not libraries. Rather, they're libraries' header files. More on that here! The string library, as @Hassan Javed said, is part of the C standard library. And it's linked by default. Libraries that are not part of the C standard library (e.g., the cs50 library) need to be linked manually with the -l flag.


2

:( greedy.c compiles \ expected an exit code of 0, not standard error of "greedy.c:7:4: error: expected identifie..." That frown :( and the fact that it is displayed in red means that your code didn't pass the compile "test". You then have all those yellow messages with a :| which means those tests never ran. Check50 shows you all the tests and color ...


2

cs50.h is a header file. Header files are NOT linked. They are included. What is linked is a library binary file. If you have successfully installed the cs50 library according to the instructions here, then follow these steps to link it by default when executing make open up a terminal window (Ctrl + Alt + T) change directories to your home directory by ...


2

Ahh I figured it out! Instead of using ~/pset1/hello/ $ go back to just the directory pset by using change directory ~/pset1/hello/ $ cd ~/pset1/ then add your ls command ~/pset1/ $ ls hello/ hello.c then compile ~/pset1/ $ clang hello.c adds the machine code to your directory and then you can execute! My only questions now is about the hello/ . ...


1

Are you using CS50 ide ? #include <cs50.h> This library will only work if you use CS50 ide for compiling your code, otherwise it will not compile


1

"after I press Run." This doesn't sound like you are using the CS50 IDE (http://cs50.io). Or, if you are, you may not have created it using the CS50 template. If you think that's the case, here are instructions


1

The detail you seem to miss is that a char array is not a string unless it ends in the NUL char '\0' If you have char text[] = "Foobar";, that is stored {'F', 'o', 'o', 'b', 'a', 'r', '\0'} Without that final NUL char, if you were to printf("%s\n", text);, printf would only stop printing when it found a NUL, which may not necessarily be after the 'r' in ...


1

The variable out is a local variable and in C the local variables are block scoped and hence the variable out in this case only exists within the block; { sprintf(fname, "%03i.jpg", fileCount); FILE *out = fopen(fname, "w"); foundFile = true; fileCount++; } Simpy move the variable declaration FILE *out to the top resembling an equivalent to;...


1

When you write d -= 0.01; do you mean d -= 1; ? Also, consider rounding after multiplication with 100. Decimal numbers like 4.2 might seem easy to write as a decimal number, but in binary that's an infinitely long number, so it's cut off after a few digits, resulting in a value slightly lower or slightly higher than the intended value.


1

I found out my problem. After a closer look at the Makefile, I realized that I only needed to type "make" into the terminal to compile all programs in speller, not make dictionary as I was doing.


1

True, the function is defined once in dictionary.h. However, the compiler sees that definition twice, the first time when it encounters #include "dictionary.h" in speller (notice the reference to speller.o on the second error line), and the second time when it encounters the same include in dictionary. You should define hash_function in dictionary.c instead....


1

The C libraries used by CS50 are all included in a default installation (std*.h, string.h, ctype.h and so on), except cs50.h of course, which you can find instructions on how to use and download and install here. Here's the getting started page for Clang where you can find instructions on how to set-up as well as links to downloads. At this point you will ...


1

It looks as though you don't have a full understanding of how directory structure works. Looking at the image that you posted, you have already created the subdirectory pset1 in the directory ~/workspace. If you look at the command line prompt, it says clairefasstner:~/workspace/pset1. That prompt gives the username before the colon and everything after the ...


1

It's not so much that compilers are overly cautious, it's that they're stupid and can't actually think. While it may be logically impossible to get through the function without hitting a return statement, the compiler doesn't see it that way. It is only smart enough to detect that all of the returns are contained in some kind of conditionals - if statements,...


1

Here's an answer to a similar problem from FaceBook: I am getting a problem in pset3. whenever i try to compile "find.c" The error goes like this: jharvard@appliance (~/Dropbox/pset3): ls breakout find jharvard@appliance (~/Dropbox/pset3): cd find jharvard@appliance (~/Dropbox/pset3/find): make find clang -ggdb3 -O0 -std=c99 -Wall -Werror find.c ...


1

That's a non-alpha ASCII value that is attempting to be printed. If you really want to know what it is, try printing it as an integer. Something along the lines of printf("the char ascii value is %i\n", name[0]). However, you have another issue. You declared name as a char array without giving it a size and without initializing it with data when declared. ...


1

I solved the cs50.h problem by updating my appliance. For updating open the terminal in the appliance and type-- update50 After the process is completed, cs50.h will work..


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)


1

String.h is a part of the C standard library. So it is automatically linked by the compiler without setting a -lstring flag.This is why you don't see an error.


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