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
2 answers

What is going wrong with fread() in my code?

Here is an excerpt of the code I'm trying now in relation to my previous problems in cs50 'Recover'. I've tried everything with fread, but for some reason it simply isn't working the way I want it to. In this loop, I'm trying to figure out how fread…
2
votes
2 answers

Problem with unload() function (CS50 Week 5: Speller)

I'm working on CS50's Week 5 assignment, Speller. I'm building my functions one at a time, and I'm running into problems with my unload function (Line 151). Right now, I'm just testing the iteration in a way that prints results before I use that…
2
votes
1 answer

Why does my SQL script select too many outputs (CS50 pset7 sql.13)?

I am currently working on pset7 in cs50, and I thought I had selected the correct number of values specified, but my script is outputting 349 rows instead of the 176 the answer key has. "In 13.sql, write a SQL query to list the names of all people…
Deece5531
  • 45
  • 4
2
votes
2 answers

Cs50's Problem Set 4 - Filter Less - Reflection Function

I have written the function to reflect an images that were provided in the zip file as .bmps. Upon some research, I've seen that many people who have solved this problem divided the width in the image by 2. However, I felt this wasn't applicable to…
2
votes
4 answers

Cs50 sepia problem with converting image from normal to sepia

I'm working on a cs50 program called filter(less comfortable, week 4), and it has to transfer images from normal to sepia. It's working fine unless it has to transfer the color white. When trying to transfer the color white, it just converts it to…
Lost in code
  • 313
  • 1
  • 4
  • 17
2
votes
1 answer

Is there a way to use get_int function in VS code?

EDIT My problem is solved Thanks all very much the problem was that I only included cs50.h but didn't include cs50.c and that the library I had was an old one containing only GetInt but not get_int when I downloaded the new library everything…
Abdo MAD
  • 19
  • 1
  • 3
2
votes
3 answers

Passing an array from a struct as an argument to a function

#include #include #include #include typedef struct { int votes; } candidate; void array_function(int arr[]); int main(void) { candidate candidates[3]; candidates[0].votes = 5; …
2
votes
1 answer

CS50/pset5/speller memory leak

Can someone help me with this? What am I doing wrong? I don't exactly know what part of this I need to fix, I think it's somewhere in the unload function. Here is my code: // Implements a dictionary's functionality #include #include…
TanTan101
  • 21
  • 2
2
votes
1 answer

Displaying "Like" and "Dislike" buttons if user has liked a post with Django

thank you for taking the time to read this. I'm working on a project for CS50W in which I have to display a series of posts which users can like and then dislike. I can successfully display the number of likes but I can't get the "Like" Button to…
2
votes
2 answers

How to wrap around alphabetically z to a and Z to A after shifting each letter by a number of places?

I am working on a code in which I shift each letter by one place, so (a) becomes (b) and (b) becomes (c) and so on. So far I managed to do that, but I am confronting a problem wrapping around the capital letter (Z) to (A). I can't seem to get the…
Bryce
  • 71
  • 8
2
votes
4 answers

How can I loop through this dictionary instead of hardcoding the keys

So far, I have this code (from cs50/pset6/DNA): import csv data_dict = {} with open(argv[1]) as data_file: reader = csv.DictReader(data_file) for record in reader: # `record` is a dictionary of column-name & value name =…
Nicolas F
  • 505
  • 6
  • 17
2
votes
0 answers

How to run jpegs recovery program written in c?

So I'm a beginner in c and I have succeeded in writing a program for cs50 pset4 that recovers photos more specifically jpeg. However I want to test my program on something else, I mean my own deleted photos. Is it possible? If yes, how? Any help…
user13806204
2
votes
0 answers

CS50 pset4 recover segmentation fault

When I compile and run my program, I get a segmentation fault. Valgrind doesn't show any problems. Any thoughts? I'm going crazy trying to figure out the problem. The point of the program is to recover JPEGS from a "forensic image" called card.raw .…
2
votes
2 answers

How do you write queries in SQL?

I am currently taking CS50, an online introductory course in coding by Harvard. We have just covered SQL and I am trying to attempt the question "Movies" in the problem set now, a description of which can be found here:…
Ethan Mark
  • 293
  • 1
  • 9
2
votes
1 answer

CS50 PSet4 - Blur Filter, I am getting black image as an output

I'm writing the code for pset4, filter, blur of cs50. But my output image is black, or it simply doesn't give the correct output. I keep running into this problem. What am I doing wrong in my blur function? void blur(int height, int width, RGBTRIPLE…
Nicolas F
  • 505
  • 6
  • 17