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
0
votes
1 answer

Why am I getting segmentation fault using strcmp?

My program should print out "Not found" not "Segmentation fault", what's happening here? This is my code #include #include #include int main(void) { string names[] = {"Bill", "Charlie", "Fred", "George", "Ginny",…
Sherri
  • 21
  • 7
0
votes
2 answers

How would I map djb2 to a hash table?

I've an assignment (CS50 - speller) where I have to implement a Hash table with linked lists. However for extra challenge we were made to implement an hashing algorithm too, I am completely new to hash tables and hashing and know 0 about…
MiguelP
  • 416
  • 2
  • 12
0
votes
0 answers

CS50 blur function does not pass check50

I am working on a CS50 problem set in which I need to do a box blur for each pixel of an image. Though my code is a bit redundant, as I had created many if loop for special cases of pixels (like edges and corners), it blurs the image as expected,…
Phu Nguyen
  • 1
  • 1
  • 1
0
votes
2 answers

passing 'person [4]' to parameter of incompatible type 'person'

Here I'm trying to write a c programming below,Here I created a data type person which has two arguments name and number (creating a name of the candidate and votes they have recieved), and when prompt for input,if user enters the name in the array…
Omkar
  • 59
  • 1
  • 9
0
votes
5 answers

Does unasigned pointers have bogus address?

So i am doing CS50 lecture 4 Memory. David says we have to assign a address when we declare int *x; as a pointer in order to store a value (Ex 45, 23 etc) in it. He also says if you don't initialize a pointer and then try to put a value in it by de…
0
votes
1 answer

Why am I receiving a NoReverseError message when having two django paths that take string inputs? (I am working on CS50 Project 1.)

I am working on CS50 Project 1 dealing with Django. In urls.py I have two paths that take strings as input, but neither work, and I receive a NoReverseError message. urls.py code urlpatterns = [ path("", views.index, name="index"), …
skateb2020
  • 129
  • 11
0
votes
0 answers

CS50 Finance: /index help displaying correct info

I've seen a few CS50 Finance help questions regarding /index. I'm trying to get the route to display a user's owned stock information (share number, value, price, etc.). Right now it displays the correct share amounts but does not display the name,…
0
votes
2 answers

Below code does not check for the existing username

I am trying to register a user. I am having problem in preventing the user to register if the username typed already exists in the database. @app.route("/register", methods=["GET", "POST"]) def register(): """Register user""" if…
Khan
  • 1
  • 1
0
votes
0 answers

My “register” function in pset9 is not working

What mistake am I doing in the code below for pset9 "register" function: @app.route("/register", methods=["GET", "POST"]) def register(): """Register user""" if request.method == "GET": return render_template("register.html") …
Khan
  • 1
  • 1
0
votes
1 answer

Segmentation fault error if argc takes only one argument. This does'nt happen when the IF is before WHILE

Check if the user provides no command-line arguments, or more, it prints Usage: ./caesar key. If the command-line argument is one then it checks if all the characters in the string are digits. If I enter ./caesar in the command line, I get a…
Annie
  • 21
  • 2
  • 10
0
votes
1 answer

How to fix errors when install Angular CLI on CS50 IDE?

I tried installing Angular CLI on CS50 IDE but it keeps getting error, I have tried some Uninstall and do npm cache clean --force Then reinstall by npm install -g @angular/cli@latest but they did not work. There are many npm WARN Here are…
0
votes
2 answers

How do i ask for input and turn the input into a variable which meets conditions to print something

I need help making my code work. I want it so the user inputs a number less than 50, if this is true it will print hello world. Otherwise the terminal will ask for another input. #include #include int main(void) { // Asking user…
Beaner21
  • 15
  • 4
0
votes
2 answers

CS50 valid triangle — incorrect code output

The code below compiles, runs, and takes input, but it does not output true or false as intended. I'm not sure what I am doing wrong. #include #include //int add_two_ints(int a, int b); bool valid_triangle (float a, float b,…
Charlesu49
  • 11
  • 4
0
votes
1 answer

Misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation]

Here I'm trying to write the C code, but I've stuck in the error, #include int main(void) { int width = 0; while (! (width >= 1) || ! (width <= 8)) { printf("Enter the width of the Pyramid: "); scanf("%i",…
Omkar
  • 59
  • 1
  • 9
0
votes
2 answers

CS50 Edge Detection bad results

I have been stuck on this for a couple of hours now every thing works fine and outputs the value it should but somehow something is wrong I even followed the program in a step by step and calculated the result of a 3 by 3 grid and I had the same…