Line numbers.
This commit is contained in:
parent
07bce58799
commit
756ef9e485
|
@ -9,10 +9,12 @@
|
|||
#include <ctype.h> /* isdigit */
|
||||
#include <limits.h> /* LONG_ INT_ _MIN _MAX */
|
||||
#include <assert.h> /* assert */
|
||||
#include "min_array.h"
|
||||
#include "../src/min_array.h"
|
||||
|
||||
struct num { size_t line; int num; };
|
||||
|
||||
MIN_ARRAY(char, char)
|
||||
MIN_ARRAY(num, int)
|
||||
MIN_ARRAY(num, struct num)
|
||||
|
||||
/** Concatenates the contents after the file pointer of `fp` to `string`. Zeros
|
||||
are preserved, as well as appending a null-terminator. @return Success,
|
||||
|
@ -37,7 +39,7 @@ int main(void) {
|
|||
int success = EXIT_FAILURE;
|
||||
struct char_array str = MIN_ARRAY_IDLE;
|
||||
struct num_array nums = MIN_ARRAY_IDLE;
|
||||
int *num;
|
||||
struct num *num;
|
||||
long big_num;
|
||||
char *a, *anum = 0;
|
||||
size_t i, line = 1 /* Unix: delimited by '\n'. */;
|
||||
|
@ -56,14 +58,16 @@ int main(void) {
|
|||
goto catch; /* Long conversion failed, (not all platforms.) */
|
||||
if(big_num < INT_MIN || big_num > INT_MAX)
|
||||
{ errno = ERANGE; goto catch; }
|
||||
*num = (int)big_num;
|
||||
num->line = line;
|
||||
num->num = (int)big_num;
|
||||
}
|
||||
fprintf(stderr, "Extracted:\n");
|
||||
for(i = 0; i < nums.size; i++) printf("%d\n", nums.data[i]);
|
||||
for(i = 0; i < nums.size; i++) printf("Line %lu: %d\n",
|
||||
(unsigned long)nums.data[i].line, nums.data[i].num);
|
||||
success = EXIT_SUCCESS;
|
||||
goto finally;
|
||||
catch:
|
||||
fprintf(stderr, "Line %lu ", line), perror("stdin");
|
||||
fprintf(stderr, "Line %lu ", (unsigned long)line), perror("stdin");
|
||||
finally:
|
||||
char_array_(&str);
|
||||
num_array_(&nums);
|
Loading…
Reference in New Issue