Questions tagged [cs50]

Code questions pertaining to Harvard's self-study introductory. It is STRONGLY RECOMMENDED to additionally tag with C or Python. Also consider using the spin-off https://cs50.stackexchange.com/

Note there is a spin-off site at https://cs50.stackexchange.com/. Consider joining the community and directing your questions there.


The CS50 (a.k.a. CSCI S-50) courses are computer science courses from Harvard University as part of its edX program.

There is a C library available at CS50 Library which provides support functions for the course.

There is also a Python library at CS50 Library which provides support functions for the course.

The tag should be used primarily for questions also tagged or (though the course does use some other languages too, and if there is a need, the extra languages would be valid too).

This tag should be used for questions which use the "cs50.h" header, python-cs50 or -lcs50 library. Another symptom that it is appropriate is the use of the type string (which is defined with typedef char *string; in the cs50.h header) or functions such as get_char(), get_double(), get_float(), get_string(), get_int(), get_long_long() and SQL().

The term 'pset' with a number (e.g. PSET5 — for Problem Set 5), with varying capitalizations is also often an indication that could be appropriate.

  • As an alternative to edx, there is a standalone website (called CS50x) where all the course materials and problem sets can be found.
  • There is CS50 Stack Exchange site dedicated to the course.
  • You can run CS50 programs in Visual Studio Code for CS50 (Codespaces)
  • The previous CS50 IDE has been deprecated. Use the Codespaces link above instead. For reference, here is the link to the previous CS50 IDE
  • CS50 has a "CS50 Sandbox" to run in a test environment. The CS50 Sandbox will be decommissioned on July 1, 2023. Sandbox URL: http://sandbox.cs50.io/ A suggested alternative after that date is Replit
3444 questions
2
votes
1 answer

What should I return when malloc returns NULL in the create_family function?

I have tried this: #include #include person *create_family(int generations) { // TODO: Allocate memory for new person person *new = malloc(sizeof(person)); if (new == NULL) { free(new); return 1; …
parmer_110
  • 325
  • 2
  • 11
2
votes
1 answer

cs50 week4 filter(less comfortable) blur and sepia function

#include "helpers.h" #include "math.h" // Convert image to grayscale void grayscale(int height, int width, RGBTRIPLE image[height][width]) { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { …
joan
  • 21
  • 2
2
votes
2 answers

Why does this program return a "?" symbol in C

I'm following along with cs50x and in problem set 2. This is the idea I had for solving the Caesar problem. I'm yet to implement the key idea due to the fact that it won't print out the word. I'm new to arrays and have searched a bit about why this…
Angus Hay
  • 23
  • 3
2
votes
1 answer

how to change design of VScode terminal when using `ls` for viewing files?

I am a beginner, thus like many, I have a fundamental question. I will appreciate it if you can help! So, I am currently using VSCode from 2 places: (1) The desktop (For everything), and (2) The web (For CS50x). When I use the ls command from the…
spacemanOG
  • 35
  • 5
2
votes
1 answer

CS50 Substitution

This problem set requires us to code a programme that takes a key from the user from the CLI and then an input (plaintext) and return a ciphertext version that is scrambled based on the key provided. My code returns the correct ciphertext given any…
smexy123
  • 45
  • 3
2
votes
2 answers

CS50 credit card validation: why is printf not printing the same number that was inputted?

I'm trying to do the credit card exercise for cs50. Why is it that when I store the credit card number as a variable called 'number' and then immediately print that variable, a random number is printed and not my entered credit card number? #include…
natalie889
  • 29
  • 2
2
votes
1 answer

How I can reduce the decimal numbers after the point and fix a bug that show a lot of words?

First, my code asks your name and it shows a random number and you need to extract the square root of it. So if the code shows 81, you need to type 9. But, when the number is decimal (1.54896 for example), I tried to write when this occurs you just…
Sanogo
  • 23
  • 4
2
votes
1 answer

CS50 Pset5 Speller - Valgrind error: Conditional jump or move depends on uninitialised value(s)

When I run this code I get the errors: ==25659== ERROR SUMMARY: 1000 errors from 1 contexts (suppressed: 0 from 0) with details from help50: ==25659== Conditional jump or move depends on uninitialized value(s) Looks like you're trying to use a…
concon817
  • 23
  • 4
2
votes
1 answer

Recover functions recovers only 4 images instead of 50

I wrote this code to recover 50 images from cs50 pset4 recover. The code can only retrieve 4 images all of which are not the right ones. It is compiling fine. When i use printf to debug it seems like the if(found) piece of code runs many times when…
2
votes
1 answer

Why we don't use a pointer in Cs50 pset4 filter's grayscale function?

Why we don't use a pointer in helpers.c? I noticed that check50 has passed for my code below, but how does it convert the variable "image" in filter.c? `#include "helpers.h" // Convert image to grayscale void grayscale(int height, int width,…
Yang00
  • 21
  • 2
2
votes
1 answer

CS50: Filter Edge Returns Mostly White Image

I have been stuck on CS50 Filter - Edges for a few days now, having a hard time determining what's wrong with my code. This code returns an almost all white images (which indicates to me final values are too large for each of the pixels). Any help…
Vlpubi
  • 23
  • 3
2
votes
1 answer

Cs50 VScode ide only running in recovery mode

Whenever I try to open the cs50 vscode workspace, it starts off by giving this notice: This codespace is currently running in recovery mode due to a container error. Review the creation logs, update your devcontainer configuration as needed, and…
spr shb
  • 81
  • 6
2
votes
2 answers

CS50 recover, when to use buffer and &buffer?

I am solved the pset4 recover in the CS50. Although I solved the problem, I am confuse between "buffer" & "&buffer". Please pay attention to "LINE AAAAA" & "LINE BBBBB". #include #include #include // New type to…
Consxious
  • 53
  • 6
2
votes
3 answers

Undeclared Identifier in do while loop, C

#include #include int main(void) { do { //ask for input with 1-8 int height = get_int("Height: "); } while (height > 0); } And I got the error code: use of undeclared identifier "height" (in the…
2
votes
4 answers

How to optimize C code with else if conditions

I'm learning some basics of C (I'm actually doing Harvard's cs50x) and I wrote this code: #include #include int main(void) { while(0 == 0) { printf("1. SUM\n2. SUBSTRACTION\n3. MULTIPLICATION\n4. DIVISION\n5.…