/**************************************************************************** * CS50 Library 2.1 * * https://manual.cs50.net/Library * * Glenn Holloway * David J. Malan * * Based on Eric Roberts' genlib.h and simpio.h. * * Creative Commons Attribution-ShareAlike 3.0 Unported License * http://creativecommons.org/licenses/by-sa/3.0/ ***************************************************************************/ #ifndef _CS50_H #define _CS50_H #include #include #include /* * Don't mix garbage-collected allocation with the system malloc-free. */ #define calloc(m,n) GC_MALLOC((m)*(n)) #define free(p) GC_FREE(p) #define malloc(n) GC_MALLOC(n) #define realloc(p,n) GC_REALLOC((p),(n)) /* * Our own data type for string variables. */ typedef char *string; /* * Reads a line of text from standard input and returns the equivalent * char; if text does not represent a char, user is prompted to retry. * Leading and trailing whitespace is ignored. If line can't be read, * returns CHAR_MAX. */ char GetChar(void); /* * Reads a line of text from standard input and returns the equivalent * double as precisely as possible; if text does not represent a * double, user is prompted to retry. Leading and trailing whitespace * is ignored. For simplicity, overflow and underflow are not detected. * If line can't be read, returns DBL_MAX. */ double GetDouble(void); /* * Reads a line of text from standard input and returns the equivalent * float as precisely as possible; if text does not represent a float, * user is prompted to retry. Leading and trailing whitespace is ignored. * For simplicity, overflow and underflow are not detected. If line can't * be read, returns FLT_MAX. */ float GetFloat(void); /* * Reads a line of text from standard input and returns it as an * int in the range of [-2^31 + 1, 2^31 - 2], if possible; if text * does not represent such an int, user is prompted to retry. Leading * and trailing whitespace is ignored. For simplicity, overflow is not * detected. If line can't be read, returns INT_MAX. */ int GetInt(void); /* * Reads a line of text from standard input and returns an equivalent * long long in the range [-2^63 + 1, 2^63 - 2], if possible; if text * does not represent such a long long, user is prompted to retry. * Leading and trailing whitespace is ignored. For simplicity, overflow * is not detected. If line can't be read, returns LLONG_MAX. */ long long GetLongLong(void); /* * Reads a line of text from standard input and returns it as a string, * sans trailing newline character. (Ergo, if user inputs only "\n", * returns "" not NULL.) Leading and trailing whitespace is not ignored. * Returns NULL upon error or no input whatsoever (i.e., just EOF). */ string GetString(void); #endif