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

CS50 Pset3 error: expected identifier or '('

I'm doing PSET3 through CS50 and I am having an issue compiling the code. It keeps on coming up with the error plurality.c:44:21: error: expected identifier or '(' candidate[i].name = argv[i + 1]; This is strange, as this is in the section…
EdCase
  • 119
  • 2
  • 7
2
votes
0 answers

Printing file content, help for understanding different outputs

I'm learning C and I've encounter a behaviour that I have hard time to understand, this is in the context of an assignment but it is not the assignment itself, just to clarify. I have a file that supposedly contains jpeg images. I open it and just…
Spleen
  • 21
  • 1
2
votes
1 answer

CS50 blur function does not pass check50, even though image is being blurred

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 8 if statements for special cases of pixels (like edges and corners), it blurs the image as expected,…
qwert9988
  • 118
  • 13
2
votes
2 answers

Readability cs50 problem with float and round

I've tried everything but I can't figure out the bug in my code. Getting the user inupt and counting the letters int main(void) { int letters = 0; //Getting user input string text = get_string("Text: "); //Counting the letters for (int i = 0; i <…
Tamara N
  • 73
  • 7
2
votes
1 answer

Why does using a while loop make the program work but my original for loop doesn't work? (DNA pset6)

just finished pset6 DNA but I am confused. When counting the consecutive dna sequences, if I used a for loop to iterate through the dna sequence text, my code would always produce 'No Match' as the output, but if I change it too a while loop to…
Will H.
  • 21
  • 1
2
votes
1 answer

CS50 pset3 Runoff

I'm stuck at the very beginning on the CS50 pset3 Runoff. Ive used several external resources but nothing is making sense. Please help me, this set has me about to quit because I do not understand. Here are the instructions: The function takes…
cwarner11
  • 21
  • 1
  • 2
2
votes
2 answers

Why do these parentheses give different answers in C?

I was working on readability for CS50 PS 2, and was getting incorrect outputs on the grade level. Debugging showed that the input values were correct, but the output was wrong. Hand calculating using the inputs gave the correct answer. I…
2
votes
2 answers

CS50 Caesar program is working but check50 says it isn't

I created this program but I'm getting errors on CS50 showing that I didn't do any of it correctly. The requirements are as follows: Implement your program in a file called caesar.c in a directory called caesar. Your program must accept a single…
2
votes
2 answers

CS50 DNA works for small.csv but not for large

I am having problems with CS50 pset6 DNA. It is getting all the right values and gives correct answers when I use the small.csv file but not when I use the large one. I have been going through it with debug50 for over a week and can't figure out the…
vexedpython
  • 33
  • 1
  • 3
2
votes
2 answers

C: Nested loop over 2d array giving unexpected result

This is a minimal reproducable example of the problem. Having height and length as parameters (rather than calculate them) is deliberate. typedef struct { int red; } triple; int main(void) { triple array[3][3] = { { {.red = 10}, {.red…
Listya
  • 23
  • 4
2
votes
1 answer

Spell checker program, check function speller cs50

This program works as a spell checker, it reads a dictionary file to load into the hash table, then reads another text file that will be read and will check every word if it is in the hash table, if not then it is considered a misspelled word. All…
Ojou Nii
  • 244
  • 4
  • 11
2
votes
2 answers

How to store a values with a min and max size in c

I'm trying to create a program which asks for a 13-16 digit credit card number, and re-prompts if the user enters non-numerical values. So far my program works when I enter 16 digit values; however, it re-prompts if I enter anything less. How do I…
Patrick Dankyi
  • 99
  • 1
  • 1
  • 7
2
votes
3 answers

Recursive function in C (to print a piramid of #)

I´m following the famous course cs50. During a class, the teacher showed a program that printed out a pyramid of a height given as an input from the user: #include #include void pyramid(int n); int main (void) { int height =…
program101
  • 27
  • 4
2
votes
3 answers

Am I dividing in the right way in C?

I need to apply a formula to three variables. Some of the operations (divisions) give me a 0 instead of the proper number. So I get a different result from what I expected from the formula. I think that the problem is related to the way C manages…
Mberu
  • 33
  • 4
2
votes
1 answer

What's wrong with my code for CS50 runoff problem?

The goal is to mimic a ranked-choice voting system wherein the voters will vote for all the candidates an rank them based on their preference. For a candidate to win he must have more than 50% votes. Output: ./runoff Alice Bob Charlie Number of…
Ojou Nii
  • 244
  • 4
  • 11