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

fgetc not displaying correctly after space

#include #include #include int main() { FILE *userfile, *pwfile, *usernamesPasswords, *readUsernamesPasswords; char u, p, user[20][25], pass[20][20], userLine[25], passLine[20]; int…
John
  • 31
  • 1
3
votes
5 answers

Variable types in C and who keeps track of it

I am taking a MOOC course CS50 from Harvard. In one of the first lectures we learned about variables of different data types: int,char, etc. What I understand is that command (say, within main function) int a = 5 reserves a number of bytes (4 for…
zesy
  • 481
  • 5
  • 12
3
votes
3 answers

Debugger skipping a whole if statement

/** * Copies a BMP piece by piece, just because. * All we have to do is change all the red pixels to */ #include #include #include "bmp.h" int main(int argc, char *argv[]) { // ensure proper usage if (argc !=…
sruly
  • 115
  • 9
3
votes
1 answer

Why isn't modulo operator working inside printf function in C?

When I remove "%97" then code works and prints what it expected. Like if input is "a" then it prints "f" whereas it doesn't works when that modulo 97 is present and prints whitespace. What is reason behind this problem? How to solve it? int…
Yash Gupta
  • 35
  • 6
3
votes
4 answers

Mario CS50 in Python

so I tried coding the mario assignment from CS50 in python instead of C to challenge myself and I managed to get it to work! I don't quite understand how the loops are working, especially the math because I just played around to get the result I…
Ivan Leo
  • 33
  • 1
  • 1
  • 5
3
votes
2 answers

Why does my while loop keep executing even when the value is true?

I tried using the Do While loop originally but was having the same results as the while loop. The user must enter a number 28 - 31. Upon the first try if the user would enter the value correctly it would move on to the next part of the code.…
3
votes
3 answers

Can't define a variable

The compiler throws an 'unused variable error', when I try to declare any type of variable and assign it a value. Below I use 'float' as the variable type and try and assign it to 1.5. #include #include int main(void) { …
David Hancock
  • 1,063
  • 4
  • 16
  • 28
3
votes
2 answers

greedy algorithm (with coins) in C

In my code I usede the greedy algorithm in order to use the minimum amaount of coins. For example: I must return $0.41, the minimum amount of coins I can use is 4: 1 - 0,25; 1 - 0.10; 1 - 0.05; 1 - 0.01; There are 4 types of coins:…
Daniel Yefimov
  • 860
  • 1
  • 10
  • 24
3
votes
3 answers

Where is the mistake in my code to perform Binary Search?

I was writing up code for a binary search algorithm. Code: #include "cs50.h" int main(void) { int n = GetInt(); int value = GetInt(); int values[n]; for (int i = 0; i < n; i++) { printf("Put in number %i ", i + 1); …
Vinz.R
  • 77
  • 1
  • 7
3
votes
7 answers

C - Why is my function returning NULL?

I think my function is returning NULL since I initilize it to it. But I get compiling error if I dont. This is just a prototype that I made in a test.c file to test it. So when I get it to work I will copy back the lookup function back into the…
mrfr
  • 1,724
  • 2
  • 23
  • 44
3
votes
1 answer

Valgrind newbie, can't seem to make it happy

I'm working through the CS50 course online, and the task at hand is to load a dictionary into memory (I'm using a chained hash table data structure), and check the contents of a text file against the words in the dictionary. I wrote a load()…
jakewies
  • 342
  • 6
  • 18
3
votes
2 answers

warning: implicit declaration

I have an assignment I am supposed to turn in for my computer science MOOC CS50. In it I have to turn in the assignment over the Harvard website, but it won't accept my code while it says "Warning: implicit declaration..." Is there a way to shut…
JonnyTruelove
  • 97
  • 1
  • 1
  • 6
2
votes
2 answers

infinite loop in cs50 speller assignment

I was working on the cs50 speller assignment, and once I finished debugging the load function, the program just ran in an infinite loop without doing or printing anything. // Implements a dictionary's functionality #include #include…
2
votes
1 answer

Returning an array to a linked list

// Implements a list of numbers using a linked list #include #include #include #include typedef struct node { int number; struct node *next; } node; node *makelist(int argc, char *argv[]); int…
Harr
  • 101
  • 5
2
votes
0 answers

CS50 PSET3 input of EOF halts program Felipes Taqueria

So my code kinda correct when seeing all the steps neccesary for the code to run and output but when checking i got Error for input of EOF halts program this is my code d = { "Baja Taco": 4.00, "Burrito": 7.50, "Bowl": 8.50, …