Skip to main content
11 votes

How can I get the cs50.h to run in Visual Studio Code?

Following are the steps to get the CS50 libraries installed in VSC in Windows 10 with mingw64 environment: Pre requisite: Install Mingw64 to set up VSC for C/C++ programming https://www.youtube.com/...
rush dee's user avatar
  • 219
10 votes

Pset3: Plurality - Weird output!

You should rethink your logic for the print_winners function. Here's the pseudocode I'd use. Declare a maxvote int set to 0. Iterate over the list of candidates and check the number of votes. If ...
curiouskiwi's user avatar
  • 18.7k
10 votes

How can I get the cs50.h to run in Visual Studio Code?

I was able to get mine working on my Mac with Visual Studio Code as follow: Assuming you have Visual Studio already installed and with all C/C++ extensions required for compiling and running C codes, ...
Jerome S. Patrick's user avatar
7 votes
Accepted

CS50 IDE undefined reference to `get_int'

On which version of the workspace are you? The current version as of 2017-11-13 is v125. If update50 doesn't end in an error message, you probably are at that version. Also, how do you compile? The ...
Blauelf's user avatar
  • 21k
6 votes
Accepted

implicit declaration of function is invalid in C99

Sorry, beginner error: But now if we try to print_name(s) in our main function, we still get an error. And that’s because the compiler reads from top to bottom, in order, so at the time main ...
Max Makhrov's user avatar
6 votes
Accepted

Pset2 Readabilty: Why are my grade levels calculating incorrectly?

This is integer division. When you divide two integers, the result is an integer again, truncating the result, ignoring its fractional part. You can turn it into floating point division by making at ...
Blauelf's user avatar
  • 21k
5 votes

pset3 (runoff) keep getting print_winner error when using check50

All you have to do is add \n after %s. (No space in between). Thank @rassenguy
StrictHornet's user avatar
4 votes
Accepted

pset4 recover: recovered images seems to still be corrupted

if (jpegsFound > -1) Shouldn't that be an else if? Your current code says: read in 512 bytes if it's a signature close file (if open) open new file increment counter ...
curiouskiwi's user avatar
  • 18.7k
4 votes

pset4 recover: recovered images seems to still be corrupted

I agree with Brenda's answer above. But also, you're initialising jpegsFound to 0. That's the value it will have before any signatures were found. Are you sure you want to write to the file when ...
Irene's user avatar
  • 1,687
4 votes

Help with blur filter for pset4! Output image is significantly darker than input

Got the solution. Using the BYTE type to store the color values resulted in overflow. Solving by using int or double for redAvg, greenAvg, and blueAvg.
Michael Weiser's user avatar
4 votes
Accepted

PSET 3 Plurality - Program works but also returns invalid vote?

Pretty straightforward problem. Your vote function ALWAYS returns false, even after registering the vote. If false is returned to main, it'll print the invalid vote message. If vote() succeeds in ...
Cliff B's user avatar
  • 69k
4 votes
Accepted

variable used in loop condition not modifies in loop body

Well, I had to think carefully about what the code is doing. That mostly comes from not using a best practice. Here's the best-practice guideline on whether to use a FOR loop or a WHILE loop. When ...
Cliff B's user avatar
  • 69k
3 votes
Accepted

CS50 PSET2 Check 50 Hello world trouble. Caesar cipher segmentation fault and encipher the plaintext

isupper() does not work on strings, it only works on chars, that's why you get the seg fault. "I did not find anything that helped to iterate over the chars of p. Can you give me a hint on how to do ...
Mahmoud Khaled's user avatar
3 votes
Accepted

C vs Python in MOOCs?

You can find the "official" answer from David Malan himself here: "Why does CS50 at Harvard use C as its primary language?" A few words from my own perspective... I began my formal programming ...
Peter's user avatar
  • 1,410
3 votes
Accepted

jpg's fourth byte

& is bitwise AND, the 0xf0 is sometimes referred to as a bit-mask, as the operation sets certain bits to 0. Both operands are integers, interpreted in their binary representation. The result has a ...
Blauelf's user avatar
  • 21k
3 votes
Accepted

Recover.c does nothing

I too have been having the same issue, but I would suggest a few edits that may help get your code working. The biggest issue I see with your code right now is that, after checking the first 512-...
Coby Z's user avatar
  • 58
3 votes
Accepted

Easiest method to organize code

You went down the rabbit hole with this pset. You chose the wrong path at the fork on the road. Just think for a minute how mush you will have to change, if instead of 5 letters which is the current ...
ChrisG's user avatar
  • 7,396
3 votes
Accepted

cs50/pset2/vigenere: Code works but check50 rejects 2 item

You are printing garbage values in the final printf statement: printf("ciphertext: %s\n", cipher); //printing of ciphered text You are asking it to print cipher as a string. You declared cipher as ...
robert_x44's user avatar
3 votes
Accepted

Pset4 Recover: Program creates segmentation fault

There are a couple of problems in the code. Ordinarily, I'd suggest that you need to identify which line is causing the seg fault, but it looks like you're stalled out on that. In this case, running ...
Cliff B's user avatar
  • 69k
3 votes
Accepted

strings an arrays

Follow the numbers. Decimal 1769234766 = hex 6974614E. Now, look at the hex pairs, stored right to left: 4E = N 61 = a 74 = t 69 = i The line feed is easy enough to understand. I'll leave it to ...
Cliff B's user avatar
  • 69k
3 votes

I can´t get (pset1) greedy/cash.c pennies to work properly!

Perhaps you don't understand float imprecision fully enough. If you were to print the value of ch with more digits of precision, you would see what's happening. Try using the following: printf("%0....
Cliff B's user avatar
  • 69k
3 votes
Accepted

cs50 pset1 mario math wrong or order?

There's a couple of problems. First, height is essentially a constant after it is entered by the user. It represents the number of rows to print, and as such, shouldn't be changed by the program. It ...
DinoCoderSaurus's user avatar
3 votes
Accepted

:( recovers 049.jpg correctly recovered image does not match

You did not check the result of fread(). Before using the result, you should check for errors. And if there are no errors, you should check how many bytes were read, before writing 512 bytes to the ...
Peter Pesch's user avatar
  • 1,009
3 votes

PSET4, Recover - Generated JPGs are blank

I think you complicate your program unnecessarily with calls to functions that do not clarify the code, recover can be done in a simpler way, and personally I always look for the greatest possible ...
MARS's user avatar
  • 5,169
3 votes
Accepted

PSET4, Recover - Generated JPGs are blank

Mars is right, the code is too complex. Too much complexity around opening, closing, and testing for open files. It's understandable that when code is executed repeatedly, you'd want to create a ...
Cliff B's user avatar
  • 69k
3 votes
Accepted

Caesar Cipher doesn't Print Spaces

Looking at your code, I'm guessing that you aren't following the current course (2019 CS50x). You are missing many concepts that are required. Saying that, your issue is that scanf as you've used it ...
curiouskiwi's user avatar
  • 18.7k
3 votes
Accepted

UndefinedBehaviorSanitizer:DEADLYSIGNAL, what does that mean?

It's a segmemtation fault. If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)
Cliff B's user avatar
  • 69k
3 votes
Accepted

jpg's are not proper, mix of multiple images. Can anyone tell me whats wrong?"RECOVER"

EEK! A GOTO statement!!!! We'll come back to that. The second IF statement is bad. You can't simply replace every == with != to find the opposite condition of a complex logical test. If any of ...
Cliff B's user avatar
  • 69k
3 votes
Accepted

Valgrind error on speller

I'm going to make an educated guess here. Since it's complaining about trying to allocate 2 bytes after a 46 byte allocation, this makes me think that its failing when testing the maximum word length ...
Cliff B's user avatar
  • 69k
3 votes
Accepted

Pset 2: Finding out readability level using Coleman-Liau index using C (CS50 2019)

The problem is integer division and the affect it has on the final calculation. Your (100 * letter / word) is going to evaluate as an integer, as well as your (100 * sentence / word) so both will ...
curiouskiwi's user avatar
  • 18.7k

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