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

Copy string to another address without malloc()

I'm (obviously) learning C I don't understand why would I use malloc to allocate memory for a newly copied string (they did it in cs50 memory lecture) #include #include int main(){ char *s = "Hi"; char *t; // Why the…
manhoty
  • 59
  • 5
2
votes
2 answers

My constant is changing, and I dont know why, or even how

I'm making a program that basically "ciphers" a text, by substituting the letters by other ones. So you basically run the program and enter a distribution, then enter the text you want to cipher, and it gives you back the cipher. #include…
2
votes
1 answer

"cc1: error: /usr/local/include: not a directory" after installing C library

This is the first time I install a library. I followed the instructions here. It's from an online course on programming. I'm not very Unix savvy. When I tried to compile one of the sample c files, one that #includes the cs50.h file, I get: cc1:…
iDontKnowBetter
  • 443
  • 1
  • 7
  • 19
2
votes
1 answer

Blurring an image.bmp with "box blur" technique in C

So in this project , I need to take an image.bmp file and blur it using "box blur". The instructions for Box Blurring as follows: For this problem, we’ll use the “box blur,” which works by taking each pixel and, for each color value, giving it a new…
BayLingual
  • 25
  • 5
2
votes
2 answers

CS50 pset4 - filter (less comfortable), sepia function

I wrote code for the sepia function of the filter pset. The code compiles without any errors but the output image is not entirely sepia. However, after I wrote the code in different way it works fine. Can someone explain why this happens? First…
Santhosh L
  • 23
  • 2
2
votes
1 answer

Unable to get output even though my logic is working

I have created a program in C. The program is a version substitution string. I have analyzed the program carefully by using the printf statements. My program logic is working correctly. However I am not able to add or concatenate strings. I am not…
killerprince182
  • 455
  • 2
  • 12
2
votes
0 answers

Why does a "more '%' conversions than data arguments" error message output a large negative integer as the first number? And why the 0's afterwords?

So I'm learning C. I'm trying to mess around on a web-based IDE called https://replit.com/languages/c . I decided I would learn to code a counter function that goes from 1 to 100(using a for loop iterator). I did this successfully with the following…
2
votes
4 answers

C if statement, optimal way to check for special characters and letters

Hi folks thanks in advance for any help, I'm doing the CS50 course i'm at the very beginning of programming. I'm trying to check if the string from the main function parameter string argv[] is indeed a number, I searched multiple ways. I found in…
FatSumo
  • 79
  • 7
2
votes
1 answer

CS50 Recover - fread into buffer

I am working on CS50 Recovery and I am unable to get the program to check the JPEG starting header. I used debug50 and added a couple print statements to try and find the problem. Every time I run the program, it prints out "No Output File 2"…
2
votes
2 answers

How do I read a SQLite database in Python on VSCode?

I have learned on CS50 that we can configure a Library to use SQLite database, on CS50 IDE, by doing this: from cs50 import SQL db = SQL("sqlite:///finance.db") Now I would like to do it in Visual Studio Code. But terminal returns me the following…
ARNON
  • 1,097
  • 1
  • 15
  • 33
2
votes
2 answers

Can anyone explain me what am I doing wrong with the loops in my program?

I am new to C and was making a program where a hash grid is drawn and the user inputs the dimensions of a grid. I also used the cs50 Library to get a int. When ever I input the dimensions, no hashes show up. Please help me. Thanks in…
AouxWoux
  • 71
  • 5
2
votes
0 answers

Why sometimes the name="btnI" doesn't work like proper google's "I'm Feelin Lucky" button?

The problem is with this type of code:
Xalava
  • 21
  • 3
2
votes
2 answers

Is there anyway to use a file pointer outside of a if condition in C

My problem starts from the while loop. I have an if condition and inside of the if condition I create a file and write to it. But naturally, I can't use the pointer outside of the condition. I'm new to C and I'm looking for a way to make that…
Baran Aldemir
  • 71
  • 1
  • 7
2
votes
1 answer

CS50 Mario, code will compile but wont do anything

I'm very new to programming and I'm trying to complete the cs50 course without just copying other people's code and trying to understand why mine won't work. Currently working on the first C assignment to create a pyramid of #s but, when I run this…
2
votes
2 answers

My program runs correctly while debugging, but incorrectly when out of debugging

I'm currently in the middle of writing a simple program in C that takes a command line argument from the user that is a substitution cipher key. Currently, my program is checking for all the possible incorrect arguments the user might enter. Running…
bmorozov
  • 41
  • 4