Hot answers tagged

5 votes
Accepted

Week 1 compiling String.c using clang instead of make

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=...
user avatar
4 votes
Accepted

What is the difference between ++i and i++?

x++ - Post-increment operator ++x - Pre-increment operator In short, x++ - x is incremented after the current statement is evaluated. ++x - x is incremented before the current statement is evaluated. ...
user avatar
4 votes
Accepted

Why do I not have to link stdio.h while compiling with clang?

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 ...
user avatar
  • 1,369
3 votes

How should I take notes for the lectures?

you don't have to do that because there are already notes for each lecture in a PDF form which you can find under each lecture video in edX. you may still want to take your own notes (maybe even on ...
3 votes
Accepted

Do we need to return 0 in C?

Typically and according to the standard, the return value of main should be of type int which obviously means that you should return an int value from main. However, you don't really have to do that ...
user avatar
  • 17.4k
3 votes
Accepted

hello.c when I want to run it says:No such file or directory

I suppose this is your hello-world program #include <stdio.h> int main(void) { printf("hello, world\n"); return 0; } which is SAVED as hello.c in your Dropbox folder. Use the ...
user avatar
  • 3,326
3 votes
Accepted

Is there a mistake in the slides of Section 1?

According to this wikipedia entry: The number 0 is neither positive nor negative and appears in the middle of a number line. So asking for a positive number does in fact exclude zero.
user avatar
  • 2,625
2 votes
Accepted

Trying to compile f2c.c from walkthrough week1 without success

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 (~) : ./...
user avatar
  • 3,326
2 votes
Accepted

Where is the CS50 style guide document?

Styles are important because they specify good coding habits, which gives you comfort when working in a team, as everyone would be following the same convention, so it will be easier for others to ...
user avatar
  • 3,326
2 votes
Accepted

Can't use get_long_long();

Does cs50.h have a function called get_long_long?. There is no function by that name listed in the CS50 Reference. And notice this from the spec: Now, get_long itself will reject hyphens (and more) ...
user avatar
1 vote
Accepted

Week 1 Credit; Not Creating Variable

The program is stuck in an infinite loop. Look at the while loop setup: while(credit_number >= 0) // runs the loop until the credit card number is l { i = credit_number % 10; credit_number = ...
user avatar
  • 64.2k
1 vote
Accepted

how do i write pesudocode.txt for Mario? (less comfortable)

You make a new file by clicking the green plus sign at the top, next to where it says the name of the file you are currently on. On your keyboard, then do command shift S. It will give you options for ...
user avatar
  • 67
1 vote

Else If Boolean Statements of Equality In the Case of Complex Numbers

That example doesn't say what data type x and y are, but generally you can assume that numerical variables are real numbers in programming, unless specified otherwise. There is a way to work with ...
user avatar
  • 709
1 vote
Accepted

Transform function into a loop or similar

Its good that you're thinking about how to make the code more efficient. Kudos to you! Yes, repeating code is a red flag that things can be simplified. But here, the code is very similar but not the ...
user avatar
  • 64.2k
1 vote

Week 1 cash.c assignment: How can I get a variable to mutate as it gets operated on?

About the first error in line 10 , you cant declare a vatiable twice , you can only assign it more than once , so you need to delete the float type declaration which is inside the do while loop. When ...
user avatar
1 vote
Accepted

get_int variable in mario causing errors

It's an issue called variable scope, something that will be explained later. Simply put, a variable only exists within the surrounding pair of curly braces where it is created. In Prof. Malan's ...
user avatar
  • 64.2k
1 vote
Accepted

Week 1: get_int & get_string errors

Solved! I ran "update50" in the terminal twice, and after the second time a prompt came up that told me I'm currently running "pip 9.0.1" and there is an update available for "pip 10.0.1", and told ...
user avatar
  • 19
1 vote

Week 1: get_int & get_string errors

Your line numbers in code and in the error messages don't match, are off by one, so I'd guess you forgot to save, or compiled something else (another file, maybe of the same name in a different ...
user avatar
  • 20.7k
1 vote
Accepted

Switch(c) undeclared identifier

Simply put, c doesn't exist because it was never declared, and no value has been assigned to it. I could explain in detail, but the following site has already done it very nicely, including an ...
user avatar
  • 64.2k
1 vote

Can't compile adder from week 1

It's a syntax error. A comma is missing before the z in line 11.
user avatar
  • 64.2k
1 vote

week 1 string.c errors

Be sure to save before making your program!
user avatar
  • 17.4k
1 vote

Last program from the first half of the lecture in week one?

Follow the link in the source code to the ioccc page. Follow some of the links to find out what it's all about. It's very cool. Then search the original page for "thad" (it's a winning entry from 2000)...
user avatar
1 vote
Accepted

Why does PrintName return void?

Good question. There is no requirement to capture a return value. Just because a function returns a value doesn't mean that the calling code needs to do anything with it. For many functions, like ...
user avatar
  • 64.2k
1 vote

why is no "\n" needed after GetString?

When you run this program, you indicate to the computer that you are finished entering your name by doing something. That "something" is where the new line in question comes from.
user avatar
1 vote
Accepted

CS50 Appliance compiling error!

Say you have written a program named example.c First you compile your program like so make example Then you run it like so ./example I tell you these because I see you have tried many times to do ...
user avatar
  • 7,326
1 vote
Accepted

Week 1 - Conditions - error expression result unused (expect ; at end of if else)

The if/else if/else conditions are used in the following way: Single condition if (condition) { // code to execute } Double condition if (condition) { // code to execute } else { // ...
user avatar
  • 7,326
1 vote

Week 1 - Conditions - error expression result unused (expect ; at end of if else)

else is your last resort kind of command its like if this then { do this } or else if this then { do that } and finally when you cant think of any other condition you say you know what MR ...
user avatar
1 vote

week 1 get 4 errors when compiling hello-1

Have you watched the lectures and/or the sections for week 1? Being able to research the correct syntax is a vital skill. The data you pass to printf must be encapsulated in parentheses. printf ( "...
user avatar
  • 42
1 vote

Permission Denied in pset1

Actually, you don't really have a problem. You just need a little instruction on a couple of nuances that you're tripping on. First, make is saying up to date because the output of the compiler, file ...
user avatar
  • 64.2k
1 vote

CS50 commands, standard commands - is there any literature and who did that?

Some of the "Shorts" in Week 0 and Week 1 dip a little into this (not much!) but they do provide a little insight into where you can go and do further research to find out the answers you may be ...
user avatar

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