Skip to content

Commit 72f7336

Browse files
Use longer example buffer to avoid complicated buffer management in reads-stdin.c.
Co-authored-by: Robert Schumacher <[email protected]>
1 parent 92dee28 commit 72f7336

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/reads-stdin.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,20 @@ const char expected_repeat[] = {'e', 'x', 'a', 'm', 'p', 'l', 'e'};
99

1010
int main(int argc, char** argv)
1111
{
12-
size_t consumed_prefix = 0;
12+
char buffer[20];
13+
const char expected[26] = "exampleexampleexampleexamp";
14+
size_t offset = 0; // always between 0 and 6
15+
for (;;)
16+
{
17+
size_t read_amount = fread(buffer, 1, sizeof(buffer), stdin);
18+
if (argc > 1) puts(argv[1]);
19+
if (read_amount == 0) {
20+
if (feof(stdin)) { puts("success"); return 0; }
21+
return 1;
22+
}
23+
if (memcmp(buffer, expected + offset, read_amount) != 0) return 2;
24+
offset = (offset + read_amount) % 7;
25+
}
1326
char buffer[20];
1427
for (;;)
1528
{

0 commit comments

Comments
 (0)