Skip to content

Commit 49fa160

Browse files
author
Kareem Zidane
authored
Merge pull request #183 from cs50/develop
adds back get_long_long for Windows
2 parents e591d85 + ee9052d commit 49fa160

File tree

5 files changed

+50
-65
lines changed

5 files changed

+50
-65
lines changed

Diff for: .travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ deploy:
8484
- <<: *deb
8585
dist: ubuntu/bionic
8686

87+
# 19.04
88+
- <<: *deb
89+
dist: ubuntu/disco
90+
8791
# Fedora
8892
- <<: *rpm
8993
dist: fedora/24

Diff for: Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION := 9.0.2
1+
VERSION := 9.1.0
22
MAJOR_VERSION := $(shell echo $(VERSION) | head -c 1)
33

44
# installation directory (/usr/local by default)

Diff for: docs/eprintf.3

-64
This file was deleted.

Diff for: src/cs50.c

+37
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,43 @@ long get_long(const char *format, ...)
397397
}
398398
}
399399

400+
/**
401+
* Prompts user for a line of text from standard input and returns the
402+
* equivalent long long; if text does not represent a long long in
403+
* [-2^63, 2^63 - 1) or would cause underflow or overflow, user is
404+
* prompted to retry. If line can't be read, returns LLONG_MAX.
405+
*/
406+
long long get_long_long(const string format, ...)
407+
{
408+
va_list ap;
409+
va_start(ap, format);
410+
411+
// Try to get a long long from user
412+
while (true)
413+
{
414+
// Get line of text, returning LLONG_MAX on failure
415+
string line = get_string(&ap, format);
416+
if (line == NULL)
417+
{
418+
va_end(ap);
419+
return LLONG_MAX;
420+
}
421+
422+
// Return a long long if only a long long (in range) was provided
423+
if (strlen(line) > 0 && !isspace((unsigned char) line[0]))
424+
{
425+
char *tail;
426+
errno = 0;
427+
long long n = strtoll(line, &tail, 10);
428+
if (errno == 0 && *tail == '\0' && n < LLONG_MAX)
429+
{
430+
va_end(ap);
431+
return n;
432+
}
433+
}
434+
}
435+
}
436+
400437
/**
401438
* Called automatically after execution exits main.
402439
*/

Diff for: src/cs50.h

+8
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ int get_int(const char *format, ...) __attribute__((format(printf, 1, 2)));
9494
*/
9595
long get_long(const char *format, ...) __attribute__((format(printf, 1, 2)));
9696

97+
/**
98+
* Prompts user for a line of text from standard input and returns the
99+
* equivalent long long; if text does not represent a long long in
100+
* [-2^63, 2^63 - 1) or would cause underflow or overflow, user is
101+
* prompted to retry. If line can't be read, returns LLONG_MAX.
102+
*/
103+
long long get_long_long(const string format, ...) __attribute__((format(printf, 1, 2)));
104+
97105
/**
98106
* Prompts user for a line of text from standard input and returns
99107
* it as a string (char *), sans trailing line ending. Supports

0 commit comments

Comments
 (0)