cs50/libcs50
FreeThis is CS50's Library for C.
FreeFree tier
About cs50/libcs50
CS50 Library for C is a lightweight C library developed by Harvard University's CS50 course to simplify input handling for beginners. It provides functions like get_int, get_string, get_float, get_double, get_char, get_long, and the deprecated get_long_long for reading various data types from standard input with built-in error checking and input flushing. The library is open source under GPL-3.0, supports Linux and macOS via package managers or source installation, and includes man pages and CS50 Reference documentation. It is widely used in introductory computer science education to reduce boilerplate and focus on programming concepts.
Key Features
Functions for reading char, double, float, int, long, and string input
Easy installation via package managers (Ubuntu, Fedora) or from source
Manual pages and CS50 Reference documentation provided
Cross-platform support for Linux and macOS
GPL-3.0 licensed open source
Used in Harvard University's CS50 introductory computer science course
Pros & Cons
Pros
- Free and open source with permissive GPL-3.0 license
- Reduces boilerplate code for input handling, ideal for beginners
- Well-documented with man pages and online reference
- Easy to install on popular Linux distributions via scripts
- Actively maintained with recent releases (v11.0.3, June 2024)
- Lightweight and focused on core input functionality
Cons
- Limited to input functions only, not a general-purpose C library
- Deprecated function (get_long_long) may cause confusion
- No official Windows package; installation on Windows requires manual compilation
- Requires linking with -lcs50 and setting environment variables for proper use
Best For
Learning C programming basicsTeaching introductory computer scienceBuilding simple command-line interactive programsCompleting CS50 problem sets and assignments
FAQ
How do I install the CS50 Library on Ubuntu?
Run the following commands in terminal: curl -s https://packagecloud.io/install/repositories/cs50/repo/script.deb.sh | sudo bash && sudo apt-get install libcs50
What should I do if I see 'cannot find -lcs50' during compilation?
Add 'export LIBRARY_PATH=/usr/local/lib' to your .bashrc file and reopen the terminal.
How do I use the library in my C program?
Include the header file with '#include <cs50.h>' and link with '-lcs50' during compilation. Then you can call functions like get_string, get_int, etc.