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

Using crypt() from crypt.h

I am doing the week2 pset for CS50. When using the crypt function, the char pointers which point to the ciphertext of any string always point to the last thing I encrypted. For example: char password[] = "AAAA"; char toCrack[] =…
Zach LeFevre
  • 81
  • 1
  • 1
  • 5
4
votes
3 answers

How do I get the printf at the end of do while loop to be executed? it just skips it

#include #include int main(void) { int min; do { printf("Minutes: "); min = get_int(); } while(min <= 0); return 0; printf("Bottles: %i\n", min * 12); } OK i am really new at c.…
Zayn
  • 61
  • 4
4
votes
1 answer

Creating a "Mario Style Pyramid"

I'm going through the Harvard CS50 online course and one of the problems is to create a "mario style pyramid" using spaces and hashes. I've got the spaces solved but the hashes are giving me trouble. Here's the code: #include #include…
roncook
  • 287
  • 3
  • 13
4
votes
2 answers

I am not sure why my code is producing this arithmetic error?

Hey everybody I am working on a program in c that tells you the least number of coins needed for any given amount of money. I have a program written that works for for every amount I have tested except for $4.20. Here is my code: #include…
4
votes
3 answers

How can I multiply a string in the C language?

I want to "multiply" a string by an int variable that the user inputs. #include #include // Height < 24 string block = "#"; string output; int main(void) { printf("Height: "); int height =…
TylerW
  • 61
  • 1
  • 1
  • 5
4
votes
1 answer

How do I add a library to my C project in Xcode 6

I am fairly new to this, but I will try to provide as detailed information as possible. I initially tried to provide a screenshot, but I can't do so without 10 reputation, so I am going to copy+paste the error messages as text at the bottom. I am…
4
votes
10 answers

Why is my loop not going infinite

#include #include int main(void) { int n; printf("Please give me an integer greater than zero!\n"); n=GetInt(); if(n<0) { printf("You are giving me a bad value!\n"); return 1; } for(int…
4
votes
7 answers

How to solve error: expected identifier or '('

I've got a problem with something I'm programming. I get this error over and over; jharvard@appliance (~/Dropbox/pset1): make mario clang -ggdb3 -O0 -std=c99 -Wall -Werror mario.c -lcs50 -lm -o mario mario.c:23:5: error: expected identifier or…
Johanna
  • 79
  • 1
  • 1
  • 5
3
votes
3 answers

Trouble understanding char* and string in CS50

So I know that a string is just an array of characters that are stored consecutively in a computer's memory. I also know that in order to find out the location of a string, you just have to go to the location of the first character as its…
3
votes
1 answer

Is there a way to make a function for calculating 10 to the x exponent in C? "ten_to_the(x exponent)"

I need to multiply a number by 10 to the (x) power, depending on the exponent I may require. I know there is a function, in the library, but I was wondering if I could make my own function to achieve basically the same but only for 10, not…
Sifnts
  • 33
  • 3
3
votes
1 answer

CS50 cash, don't understand code given by the problem

I want to understand the code give by the problem set and try to figure it out from there. I can't even start solving the problem since I don't understand the code given. I'm having a difficult time wrapping my head around all these return operators…
Meliodas
  • 63
  • 7
3
votes
2 answers

Trying to create a C program which prints out all numbers with rational square roots?

#include #include #include #include void rationalSquareRoots(void); int main(void) { rationalSquareRoots(); } void rationalSquareRoots(void) { for(float i = 0; ; i++) { if(sqrt(i) % 1 == 0) { …
UrosDjosic
  • 45
  • 4
3
votes
2 answers

Segmentation Fault while working on a Hash Table

I am just learning c with the cs50 course and I just got introduced to pointers and data structures (It is very confusing please help). So I got a project where I need to make a hash table and I started first by trying to add some nodes to the zero…
3
votes
1 answer

How do you take an id from a django model form, use it as the url, and get all the data from that value from the form?

I am doing CS50 Project 2 and need to make a webpage that takes in the id through the url and retrieves all of the information about that particular item from the database to display on the webpage. def listing(request, id): id =…
skateb2020
  • 129
  • 11
3
votes
3 answers

Why do we need to check string length larger than 0?

I got this example from CS50. I know that we need to check "s == NULL" in case there is no memory in the RAM. But, I am not sure why do we need to check the string length of t before capitalize. #include #include #include…
Consxious
  • 53
  • 6