-
Notifications
You must be signed in to change notification settings - Fork 1
/
cs50.h
103 lines (77 loc) · 2.75 KB
/
cs50.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/****************************************************************************
* CS50 Library 3.0
*
* https://manual.cs50.net/Library
*
* Glenn Holloway <[email protected]>
* David J. Malan <[email protected]>
*
* Based on Eric Roberts' genlib.c and simpio.c.
*
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
* http://creativecommons.org/licenses/by-nc-sa/3.0/
***************************************************************************/
#ifndef _CS50_H
#define _CS50_H
#include <float.h>
#include <limits.h>
#include <stdbool.h>
#include <stdlib.h>
/*
* 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