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

Are you printing an additional character at the beginning of each line? - main error left aligned pyramid

I'm currently at pset6 from cs50, mario-less. My code compiles and prints the left aligned pyramid as the problem asks, but when I do a check50, most of them fail. What is the problem? from cs50 import get_int # Ask user for input n =…
stefanp
  • 37
  • 3
3
votes
1 answer

Resizing a BMP image (making it smaller)

It seems I need some help with resizing the BMP image when the zoom factor is less than 1. You can see the most crucial part of my code below. The variable f in the code is the zoom factor. It seems logical to me but it works improperly. - this is…
SaintSammy
  • 107
  • 8
3
votes
3 answers

Error when multiplying type int to struct

The code below spits the following error when trying to compile: invalid operands to binary expression ('int' and 'RGBTRIPLE') Basically, I don't know how to properly multiply temp[i][j] to a factor. I tried typecasting like 2 * int(temp[i][j]) for…
3
votes
1 answer

Cs50 pset5 speller segmentation, memory errors

I'm doing the speller program and for the past few days I feel like I'm going in circles, receiving the same problems over and over again. Now, the error is free(): "invalid pointer Aborted", most likely refering to the hash function, in which I use…
Nichael18
  • 73
  • 4
3
votes
2 answers

CS50 Speller compiles, yet not runs at all

I'm very new to programming and I've been trying to finish the cs50 course without just copying other people's code and trying to understand why mine won't work. I'm currently stuck in pset5 (I have been for a couple of days now), the code compiles…
dani1995ar
  • 39
  • 2
3
votes
4 answers

I can't find /rootfs on Windows 10

I'm very confused with the whole WSL situation. Sometimes I feel like I get it but in reality, I don't. My main confusion is where does Ubuntu (I use Ubuntu 20.04) save files? And how do they intertwine with files I install with Windows Command…
3
votes
2 answers

Why does printf print the number of spaces I assigned to the int space?

#include #include int main(void) { int height; do { height = get_int("Size: \n"); } while (height < 1 || height > 50); for (int row = 1; row < height + 1; row++) { for (int space = height - row;…
Victor B
  • 51
  • 2
3
votes
1 answer

Readability for cs50. There valuable changes for no reason at "if" line

So I started programming 5 days ago. I'm going through course cs50. There is a task (see https://cs50.harvard.edu/x/2020/psets/2/readability/) to make a program which evaluates grade of text. I did it. #include #include #include…
VVS232
  • 43
  • 5
3
votes
1 answer

How "struct" members are indexed? How to access them correctly in C?

How the "candidate" stuct is indexed in the following code? When I try to print the last member(last index?) of the created struct which is candidates["last index"].name supposing I do have 4 candidates that will result the candidate_count which is…
The_M_Code
  • 127
  • 2
  • 10
3
votes
1 answer

For loops not running PSET6 DNA CS50x

My code always outputs "No Match", so I ran it on debug50. My counting function is right some of the time, but even when I know that it's counted STRs correctly, it output's "No Match". I ran debug50 on just the code that looks for a match, and I…
mkg15
  • 43
  • 7
3
votes
3 answers

What is the difference between an iteration and a loop?

I am doing Cs50 Harvard University online and I'm on week 3 but while watching the video I noticed that I iterations and loops seem the same, as they repeat things over and over. But there must be a difference or else they wouldn't have two names…
user13846054
3
votes
10 answers

How to check for repeated characters within a string in c

I'm trying to create a program that checks for repeated characters within the command line argument's string. The string is suppose to contain only 26 characters, and all characters have to be alphabetical. However, there cannot be any repeated…
Patrick Dankyi
  • 99
  • 1
  • 1
  • 7
3
votes
2 answers

How do I count the number of sentences in C using ".", "?", "!"?

I'm fairly new to coding. I'm having trouble with my "CountSentences" function. I compare the string to "." , "?" , and ! to count a sentence. It only adds one to the sentence counter no matter how many of the punctuation marks I have in the…
TheAfroman
  • 33
  • 3
3
votes
3 answers

How to extract individual digits from a list of integers?

Being new to python this has been giving me some trouble Given a list of integers like [2, 0, 0, 0, 0, 12, 0, 8] how might I extract the indiviual digits of each element to form a new list [2,1,2,8] I've had the idea of iterating through each…
3
votes
5 answers

How to count only letters in string?

I am trying to write a program that counts several elements in a string. The first one of those being letters. The assignment is part of the CS50 week 2 problem set, hence the libraries included. Using the while condition I was able to count every…
LauraT
  • 33
  • 1
  • 4