cs50: The CS50 Library for C ready to use with Clib
I was a CS50 student once, working with strings was easier back then while coding in C. So why not keep using it on future projects?
Well, I created this project to integrate it Clib and to be easy to use as a dependency for future projects.
If you are a CS50 student don't take this project as example to follow the style, make sure you read instead the style guide for the C Programming Language from CS50.
Installing using Clib
$ clib install abranhe/cs50
For more installation options see the official library from the CS50 team.
$ ./example
abranhe
hello, abranhe
#include <stdio.h>
#include "cs50.h"
int main()
{
string s = get_string();
printf("hello, %s\n", s);
return 0;
}
Type representing a C string. Aliased to char *
.
Prints an error message formatted like printf()
to standard error, prefixing it with file and line number from which the function was called.
format
- theprintf()
-like format string used to display the prompt...
– values to be substituted into the format string a laprintf()
Prompts user for a line of text from standard input and returns the equivalent char
; if text does not represent a single char, user is reprompted.
format
- theprintf()
-like format string used to display the prompt...
– values to be substituted into the format string a laprintf()
- the char equivalent to the line read from stdin, or
CHAR_MAX
on error
Prompts user for a line of text from standard input and returns the equivalent double
; if text does not represent a double or would cause overflow or underflow, user is reprompted.
format
- theprintf()
-like format string used to display the prompt...
– values to be substituted into the format string a laprintf()
- the double equivalent to the line read from stdin in [
DBL_MIN
,DBL_MAX
), as precisely as possible, orDBL_MAX
on error
Prompts user for a line of text from standard input and returns the equivalent int
; if text does not represent an int or would cause overflow, user is reprompted.
format
- theprintf()
-like format string used to display the prompt...
– values to be substituted into the format string a laprintf()
- the int equivalent to the line read from stdin in [
INT_MIN
,INT_MAX
) orINT_MAX
on error
Prompts user for a line of text from standard input and returns the equivalent float; if text does not represent a float
or would cause overflow or underflow, user is reprompted.
format
- theprintf()
-like format string used to display the prompt...
– values to be substituted into the format string a laprintf()
- the float equivalent to the line read from stdin in [
FLT_MIN
,FLT_MAX
), as precisely as possible, orFLT_MAX
on error
Prompts user for a line of text from standard input and returns the equivalent float; if text does not represent a long
or would cause overflow or underflow, user is reprompted.
format
- theprintf()
-like format string used to display the prompt...
– values to be substituted into the format string a laprintf()
- the float equivalent to the line read from stdin in [
LONG_MIN
,LONG_MAX
), as precisely as possible, orLONG_MAX
on error
*Prompts user for a line of text from standard input and returns it as a string (char ), sans trailing line ending. Supports CR (\r
), LF (\n
), and CRLF (\r\n
) as line endings. Stores string on heap, but library’s destructor frees memory on program’s exit.
format
- theprintf()
-like format string used to display the prompt...
– values to be substituted into the format string a laprintf()
- the read line as a string sans line endings, or
NULL
onEOF
.
For more information read the documentation at cs50.readthedocs.io/library/c
- cs50: Official CS50 Library for C
The CS50 library is owned and managed by the Team behind CS50, learn more.