/**************************************************************************** * CS50 Library 3.1 * https://manual.cs50.net/Library * * Based on Eric Roberts' genlib.c and simpio.c. * * Copyright (c) 2011, * Glenn Holloway * David J. Malan * All rights reserved. * * BSD 3-Clause License * http://www.opensource.org/licenses/BSD-3-Clause * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of CS50 nor the names of its contributors may be used * to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***************************************************************************/ #ifndef _CS50_H #define _CS50_H #include #include #include #include /* * 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 (char *), sans trailing newline character. (Ergo, if * user inputs only "\n", returns "" not NULL.) Returns NULL * upon error or no input whatsoever (i.e., just EOF). Leading * and trailing whitespace is not ignored. Stores string on heap * (via malloc); memory must be freed by caller to avoid leak. */ string GetString(void); #endif