Skip to content

Commit b4de9b3

Browse files
committed
updated comments
1 parent 28e72f5 commit b4de9b3

File tree

2 files changed

+45
-46
lines changed

2 files changed

+45
-46
lines changed

src/cs50.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ void eprintf(const char *file, int line, const char *format, ...)
8383
}
8484

8585
/**
86-
* Reads a line of text from standard input and returns the equivalent
87-
* char; if text does not represent a char, user is prompted to retry.
88-
* Leading and trailing whitespace is ignored. If line can't be read,
89-
* returns CHAR_MAX.
86+
* Prompts user for a line of text from standard input and returns the
87+
* equivalent char; if text does not represent a char, user is prompted
88+
* to retry. Leading and trailing whitespace is ignored. If line can't
89+
* be read, returns CHAR_MAX.
9090
*/
9191
char get_char(string prompt)
9292
{
@@ -115,9 +115,9 @@ char GetChar(void)
115115
}
116116

117117
/**
118-
* Reads a line of text from standard input and returns the equivalent
119-
* double as precisely as possible; if text does not represent a
120-
* double or if value would cause underflow or overflow, user is
118+
* Prompts user for a line of text from standard input and returns the
119+
* equivalent double as precisely as possible; if text does not represent
120+
* a double or if value would cause underflow or overflow, user is
121121
* prompted to retry. If line can't be read, returns DBL_MAX.
122122
*/
123123
double get_double(string prompt)
@@ -156,10 +156,10 @@ double GetDouble(void)
156156
}
157157

158158
/**
159-
* Reads a line of text from standard input and returns the equivalent
160-
* float as precisely as possible; if text does not represent a float
161-
* or if value would cause underflow or overflow, user is prompted to
162-
* retry. If line can't be read, returns FLT_MAX.
159+
* Prompts user for a line of text from standard input and returns the
160+
* equivalent float as precisely as possible; if text does not represent
161+
* a float or if value would cause underflow or overflow, user is prompted
162+
* to retry. If line can't be read, returns FLT_MAX.
163163
*/
164164
float get_float(string prompt)
165165
{
@@ -197,10 +197,10 @@ float GetFloat(void)
197197
}
198198

199199
/**
200-
* Reads a line of text from standard input and returns it as an
201-
* int in [-2^31, 2^31 - 1), if possible; if text does not represent
202-
* such an int or if value would cause underflow or overflow, user is
203-
* prompted to retry. If line can't be read, returns INT_MAX.
200+
* Prompts user for a line of text from standard input and returns the
201+
* equivalent int; if text does not represent an int in [-2^31, 2^31 - 1)
202+
* or would cause underflow or overflow, user is prompted to retry. If line
203+
* can't be read, returns INT_MAX.
204204
*/
205205
int get_int(string prompt)
206206
{
@@ -234,10 +234,10 @@ int GetInt(void)
234234
}
235235

236236
/**
237-
* Reads a line of text from standard input and returns an equivalent
238-
* long long in [-2^63, 2^63 - 1), if possible; if text does not
239-
* represent such a long long or if value would cause underflow or overflow,
240-
* user is prompted to retry. If line can't be read, returns LLONG_MAX.
237+
* Prompts user for a line of text from standard input and returns the
238+
* equivalent long long; if text does not represent a long long in
239+
* [-2^63, 2^63 - 1) or would cause underflow or overflow, user is
240+
* prompted to retry. If line can't be read, returns LLONG_MAX.
241241
*/
242242
long long get_long_long(string prompt)
243243
{
@@ -281,8 +281,8 @@ static size_t allocations = 0;
281281
static string *strings = NULL;
282282

283283
/**
284-
* Reads a line of text from standard input and returns it as
285-
* a string (char *), sans trailing line ending. Supports
284+
* Prompts user for a line of text from standard input and returns
285+
* it as a string (char *), sans trailing line ending. Supports
286286
* CR (\r), LF (\n), and CRLF (\r\n) as line endings. If user
287287
* inputs only "\n", returns "", not NULL. Returns NULL upon
288288
* error or no input whatsoever (i.e., just EOF). Stores string

src/cs50.h

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,12 @@
4747
#include <stdlib.h>
4848

4949
/**
50-
* TODO
51-
*
52-
* https://gustedt.wordpress.com/2010/06/03/default-arguments-for-c99/
50+
* Temporarily used to make arguments to get_* (but not Get*) optional.
51+
* Inspired by https://gustedt.wordpress.com/2010/06/03/default-arguments-for-c99/.
5352
*/
5453
#define _ARGS(_0, _1, _2, ...) _2
5554
#define ARGS(...) _ARGS(, ##__VA_ARGS__, 1, 0)
56-
#define ARG_0(NAME) "Retry: "
55+
#define ARG_0(NAME) NULL
5756
#define ARG_1(NAME, a) a
5857
#define __ZERO_OR_ONE_ARG(NAME, N, ...) ARG_ ## N (NAME, ##__VA_ARGS__)
5958
#define _ZERO_OR_ONE_ARG(NAME, N, ...) __ZERO_OR_ONE_ARG(NAME, N, ##__VA_ARGS__)
@@ -85,58 +84,58 @@ void eprintf(const char *file, int line, const char *format, ...) __attribute__(
8584
#define eprintf(format, ...) eprintf(__FILE__, __LINE__, format, ##__VA_ARGS__)
8685

8786
/**
88-
* Reads a line of text from standard input and returns the equivalent
89-
* char; if text does not represent a char, user is prompted to retry.
90-
* Leading and trailing whitespace is ignored. If line can't be read,
91-
* returns CHAR_MAX.
87+
* Prompts user for a line of text from standard input and returns the
88+
* equivalent char; if text does not represent a char, user is prompted
89+
* to retry. Leading and trailing whitespace is ignored. If line can't
90+
* be read, returns CHAR_MAX.
9291
*/
9392
char get_char(string prompt);
9493
char GetChar(void) __attribute__((deprecated));
9594
#define get_char(...) ZERO_OR_ONE_ARG(get_char, ##__VA_ARGS__)
9695

9796
/**
98-
* Reads a line of text from standard input and returns the equivalent
99-
* double as precisely as possible; if text does not represent a
100-
* double or if value would cause underflow or overflow, user is
97+
* Prompts user for a line of text from standard input and returns the
98+
* equivalent double as precisely as possible; if text does not represent
99+
* a double or if value would cause underflow or overflow, user is
101100
* prompted to retry. If line can't be read, returns DBL_MAX.
102101
*/
103102
double get_double(string prompt);
104103
double GetDouble(void) __attribute__((deprecated));
105104
#define get_double(...) ZERO_OR_ONE_ARG(get_double, ##__VA_ARGS__)
106105

107106
/**
108-
* Reads a line of text from standard input and returns the equivalent
109-
* float as precisely as possible; if text does not represent a float
110-
* or if value would cause underflow or overflow, user is prompted to
111-
* retry. If line can't be read, returns FLT_MAX.
107+
* Prompts user for a line of text from standard input and returns the
108+
* equivalent float as precisely as possible; if text does not represent
109+
* a float or if value would cause underflow or overflow, user is prompted
110+
* to retry. If line can't be read, returns FLT_MAX.
112111
*/
113112
float get_float(string prompt);
114113
float GetFloat(void) __attribute__((deprecated));
115114
#define get_float(...) ZERO_OR_ONE_ARG(get_float, ##__VA_ARGS__)
116115

117116
/**
118-
* Reads a line of text from standard input and returns it as an
119-
* int in [-2^31, 2^31 - 1), if possible; if text does not represent
120-
* such an int or if value would cause underflow or overflow, user is
121-
* prompted to retry. If line can't be read, returns INT_MAX.
117+
* Prompts user for a line of text from standard input and returns the
118+
* equivalent int; if text does not represent an int in [-2^31, 2^31 - 1)
119+
* or would cause underflow or overflow, user is prompted to retry. If line
120+
* can't be read, returns INT_MAX.
122121
*/
123122
int get_int(string prompt);
124123
int GetInt(void) __attribute__((deprecated));
125124
#define get_int(...) ZERO_OR_ONE_ARG(get_int, ##__VA_ARGS__)
126125

127126
/**
128-
* Reads a line of text from standard input and returns an equivalent
129-
* long long in [-2^63, 2^63 - 1), if possible; if text does not
130-
* represent such a long long or if value would cause underflow or overflow,
131-
* user is prompted to retry. If line can't be read, returns LLONG_MAX.
127+
* Prompts user for a line of text from standard input and returns the
128+
* equivalent long long; if text does not represent a long long in
129+
* [-2^63, 2^63 - 1) or would cause underflow or overflow, user is
130+
* prompted to retry. If line can't be read, returns LLONG_MAX.
132131
*/
133132
long long get_long_long(string prompt);
134133
long long GetLongLong(void) __attribute__((deprecated));
135134
#define get_long_long(...) ZERO_OR_ONE_ARG(get_long_long, ##__VA_ARGS__)
136135

137136
/**
138-
* Reads a line of text from standard input and returns it as
139-
* a string (char *), sans trailing line ending. Supports
137+
* Prompts user for a line of text from standard input and returns
138+
* it as a string (char *), sans trailing line ending. Supports
140139
* CR (\r), LF (\n), and CRLF (\r\n) as line endings. If user
141140
* inputs only "\n", returns "", not NULL. Returns NULL upon
142141
* error or no input whatsoever (i.e., just EOF). Stores string

0 commit comments

Comments
 (0)