Skip to content

abranhe/cs50

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation





cs50: The CS50 Library for C ready to use with Clib



Description

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.

Keep in mind

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.

Installation

Installing using Clib

$ clib install abranhe/cs50

For more installation options see the official library from the CS50 team.

Usage

$ ./example
abranhe
hello, abranhe
example.c
#include <stdio.h>
#include "cs50.h"

int main()
{
	string s = get_string();
	printf("hello, %s\n", s);
	return 0;
}

API

string

Type representing a C string. Aliased to char *.

void eprintf(const char *format, ...)

Prints an error message formatted like printf() to standard error, prefixing it with file and line number from which the function was called.

Params:
  • format - the printf()-like format string used to display the prompt
  • ... – values to be substituted into the format string a la printf()

char get_char(const char *format, ...)

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.

Params:
  • format - the printf()-like format string used to display the prompt
  • ... – values to be substituted into the format string a la printf()
Returns:
  • the char equivalent to the line read from stdin, or CHAR_MAX on error

double get_double(const char *format, ...)

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.

Params:
  • format - the printf()-like format string used to display the prompt
  • ... – values to be substituted into the format string a la printf()
Returns:
  • the double equivalent to the line read from stdin in [DBL_MIN, DBL_MAX), as precisely as possible, or DBL_MAX on error

int get_int(const char *format, ...)

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.

Params:
  • format - the printf()-like format string used to display the prompt
  • ... – values to be substituted into the format string a la printf()
Returns:
  • the int equivalent to the line read from stdin in [INT_MIN, INT_MAX) or INT_MAX on error

float get_float(const char *format, ...)

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.

Params:
  • format - the printf()-like format string used to display the prompt
  • ... – values to be substituted into the format string a la printf()
Returns:
  • the float equivalent to the line read from stdin in [FLT_MIN, FLT_MAX), as precisely as possible, or FLT_MAX on error

long get_long(const char *format, ...)

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.

Params:
  • format - the printf()-like format string used to display the prompt
  • ... – values to be substituted into the format string a la printf()
Returns:
  • the float equivalent to the line read from stdin in [LONG_MIN, LONG_MAX), as precisely as possible, or LONG_MAX on error

char *get_string(const char *format, ...)

*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.

Params:
  • format - the printf()-like format string used to display the prompt
  • ... – values to be substituted into the format string a la printf()
Returns:
  • the read line as a string sans line endings, or NULL on EOF.

For more information read the documentation at cs50.readthedocs.io/library/c

Related

  • cs50: Official CS50 Library for C

License

The CS50 library is owned and managed by the Team behind CS50, learn more.