22
votes
Memory overlap in C
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
++++...
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/...
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 ...
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,
...
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 ...
6
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 ...
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 ...
4
votes
understanding 3D arrays
A 2D array is an array of arrays. a 3D array is an array of arrays of arrays. in this case we have an array of 2 arrays each of which is of 3 arrays each of which is 2 elements long.
recall that, in ...
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
...
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 ...
4
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
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.
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 ...
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 ...
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 ...
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 ...
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 ...
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-...
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 ...
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 ...
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 ...
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 ...
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....
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 ...
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 ...
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 ...
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 ...
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 ...
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. ;-)
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
c × 672cs50x × 186
pset4 × 79
speller × 65
pset1 × 63
recover × 58
pset2 × 50
pset5 × 46
pset3 × 40
resize × 25
mario × 24
check50 × 23
vigenere × 23
cs50-ide × 19
credit × 19
array × 19
pointers × 18
string × 17
segmentation-fault × 15
error × 15
cs50x2019 × 15
caesar × 13
function × 13
pset6 × 11
game-of-fifteen × 11