kzidane
Moderator
  • Member for 7 years, 7 months
  • Last seen more than a week ago
pset5 getrusage in speller.c
Accepted answer
23 votes

As denoted by the man page for getrusage, it takes 2 arguments, an int and a struct rusage. before and after are of type struct rusage whose definition is struct rusage { struct timeval ru_utime;...

View answer
Is something wrong with getType(object)?
19 votes

The function detectCollision() returns NULL if there's no collision happened. You have to check whether your object is equal to NULL before you pass it to getType().

View answer
How to Use check50?
Accepted answer
18 votes

What is check50? check50 is a command-line program included in the CS50 Appliance with which you can check the correctness of (some of) your programs. What is an ID? Each program that is checkable ...

View answer
Array Initializer Must Be an Initializer List or String Literal
Accepted answer
17 votes

First, when declaring a char array, you've to specify its size within the brackets like: char arr[10]; except when you're initializing it with a string literal. And since we don't know the number ...

View answer
How to fix the "conditional jump or move depends on uninitialized value" valgrind error?
Accepted answer
15 votes

The problem is mainly caused by the if statement on line 69 if (temp->word != NULL) { // some code } valgrind is angry because you never really initialized the member word of your struct ...

View answer
Memory overlap in C
14 votes

I believe you mean memmove which takes care of memory overlapping as oppose to memset. but what is memory overlapping anyway? suppose we have an array of 5 chars, where each char is a byte long ++++...

View answer
pset5 copy.c confused in fread
Accepted answer
13 votes

Per the manual page for fread() size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream); The function fread() reads nmemb elements of data, each size bytes long, from the stream ...

View answer
What's the difference between #include <abc.h> and #include "abc.h"
Accepted answer
13 votes

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 ...

View answer
What's wrong with my code for mario?
12 votes

Five months is too long for a problem like mario or pretty much any other problem in the course. You could try solving it manually with low-tech tools (e.g., a pencil and a paper) trying to draw half ...

View answer
pset3 / move function
Accepted answer
11 votes

The move() function basically does 3 main things: receives the number on the tile to be move. validates the move. if the move is valid, it makes it and returns true. Otherwise, it returns false. ...

View answer
Why does the ball glide along the paddle whenever it touches its sides?
Accepted answer
11 votes

What really causes this problem is that the ball hits one of the paddle's sides (or corners) and the bottom of the ball actually passes the top of the paddle. let's call the distance between the ...

View answer
Why do I get the "invalid operands to binary expression" error?
Accepted answer
11 votes

The remainder operator (otherwise known as the modulo operator) % is a binary operator (i.e., takes exactly 2 operands) and operates only on integer types (e.g., short, int, long, long long, etc). It ...

View answer
Hacker4/Resize: can't resize when factor is a decimal number
Accepted answer
10 votes

There may be better approaches, but I used an algorithm called nearest neighbor and I wouldn't say my implementation was perfect. I wrote two functions, one for down-scaling and the other for up-...

View answer
Ubuntu password required when starting apache 50 - pset7
10 votes

Apologies for the inconvenience! Should be fixed ASAP! But until it's fixed, yet another solution to this is to execute: $ echo "#includedir /etc/sudoers.d" | sudo tee -a /etc/sudoers in a terminal ...

View answer
Explanation of the formula for padding
Accepted answer
10 votes

When bi.Width * sizeof(RGBTRIPLE) is a multiple of 4, the expression (bi.biWidth * sizeof(RGBTRIPLE)) % 4 gets evaluated to 0 which, it turn, gets the expression 4 - [(bi.biWidth * sizeof(RGBTRIPLE)...

View answer
What does the linker do?
Accepted answer
10 votes

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 ...

View answer
What is the difference between bfSize and biSizeImage?
10 votes

You are right! bfSize should store the size of the whole BMP file — the size of the BMP image + the size of the headers. biSizeImage should store the size of the BMP image — the size of the ...

View answer
Undefined reference to `GetString'
10 votes

A library's header file (the one that ends with the .h extension) doesn't contain function definitions. Instead, it contains the library's resources that are available for you to use. These resources ...

View answer
Stopping an infinite loop while running
Accepted answer
9 votes

Yes. To force-exit a running program, press Ctrl + C from your keyboard!

View answer
How to Compile the CS50 Library on Another Linux Distro?
8 votes

Update: please follow the instructions per https://github.com/cs50/libcs50#installation instead! A shorter answer could be this. Debian, Ubuntu First become root, as with: sudo su - ...

View answer
How to approach the psets?
Accepted answer
8 votes

I think this is typical specially if this is your first CS/programming course. Thinking: You should probably consider these points: you, as a human being, should be able to solve the problem ...

View answer
Which command is used to clear terminal (output) window?
Accepted answer
8 votes

The shortcut Ctrl + L should do the job either.

View answer
How to Declare and Initialize Variables in C?
Accepted answer
8 votes

Variables can be declared and initialized in different ways. Variable Declaration There are two common methods for declaring variables. Suppose we want to declare two int variables, x and y Method ...

View answer
How do I share a variable between source files in C with extern?
Accepted answer
8 votes

From this really long answer: Using extern is only of relevance when the program you're building consists of multiple source files linked together, where some of the variables defined, for ...

View answer
Collision of ball with other objects
Accepted answer
8 votes

The Idea Behind Collision: There's a function namely detectCollision() that's already written for you and ready to use. This function, when it's called, checks whether any of the sides of the ball ...

View answer
pset3: sort -- having trouble connecting all the dots
7 votes

Where do I implement that? In helpers.c? helpers.h? A library's .h file is a header file. It does NOT contain definitions. Instead, it contains code that declares the library's resources that are ...

View answer
not fully understanding dynamically sized array in server.c pest
Accepted answer
7 votes

of course needle and haystack both are pointers and thus they both store addresses which are essentially numbers so we can perform arithmetic operations on them. needle - haystack + 2 + 1 subtracts ...

View answer
How to Fix "control may reach end of non-void function" and "No such file or directory" Errors?
7 votes

The warning (converted to an error due to the -Werror option to clang on the appliance) control may reach end of non-void function Says that you've a function in your program that's declared to ...

View answer
Recover Buffer as uint8_t instead of int
Accepted answer
7 votes

A variable of type int is 4 bytes long on most 32-bit operating systems. If you declared your buffer to be an array of 512 ints, this means that the size of your array is 2048 bytes (4 blocks) rather ...

View answer
"Invalid ID" error when submitting mario for check50
7 votes

The correct ID is 2014/x/pset1/mario so you should run: check50 2014/x/pset1/mario mario.c

View answer
1
2 3 4 5
22