Last change
on this file since 274 was 2, checked in by Rick van der Zwet, 15 years ago |
Initial import of data of old repository ('data') worth keeping (e.g. tracking
means of URL access statistics)
|
File size:
1.3 KB
|
Rev | Line | |
---|
[2] | 1 | /* Author : Rick van der Zwet
|
---|
| 2 | * S-number : 0433373
|
---|
| 3 | * Version : $Id: compressie.cc 330 2007-11-25 23:31:30Z rick $
|
---|
| 4 | * Copyright : FreeBSD Licence
|
---|
| 5 | */
|
---|
| 6 | #include <stdio.h>
|
---|
| 7 | #include <errno.h>
|
---|
| 8 | #include <stdlib.h>
|
---|
| 9 | #include <sysexits.h>
|
---|
| 10 | #include "fileio.h"
|
---|
| 11 |
|
---|
| 12 |
|
---|
| 13 | //XXX: File are only checked at creation time, not during execution
|
---|
| 14 | int
|
---|
| 15 | main(int argc, char ** argv) {
|
---|
| 16 | FILE * input;
|
---|
| 17 | FILE * output;
|
---|
| 18 |
|
---|
| 19 | int number = 0;
|
---|
| 20 | int row = 0;
|
---|
| 21 |
|
---|
| 22 | if (argc < 2) {
|
---|
| 23 | fprintf(stderr, "Usage: %s <infile> [<outfile>]\n",argv[0]);
|
---|
| 24 | return(EX_USAGE);
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | input = fopen(argv[1], "r");
|
---|
| 28 | if (input == NULL) {
|
---|
| 29 | fprintf(stderr,"Error: Unable to use `%s', errno: %i\n",
|
---|
| 30 | argv[1], errno);
|
---|
| 31 | return(EX_NOINPUT);
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | if (argc == 3) {
|
---|
| 35 | output = fopen(argv[2], "w");
|
---|
| 36 | if (output == NULL) {
|
---|
| 37 | fprintf(stderr,"Error: Unable to use `%s', errno: %i\n",
|
---|
| 38 | argv[2], errno);
|
---|
| 39 | return(EX_CANTCREAT);
|
---|
| 40 | }
|
---|
| 41 | } else
|
---|
| 42 | output = stdout;
|
---|
| 43 |
|
---|
| 44 |
|
---|
| 45 | while ((number = fetchnumber(input)) != FILE_END) {
|
---|
| 46 | fprintf(output,"%04i ", number);
|
---|
| 47 | row++;
|
---|
| 48 | if (row == 15) {
|
---|
| 49 | printf("\n");
|
---|
| 50 | row = 0;
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | fprintf(output,"\n");
|
---|
| 55 | fclose(input);
|
---|
| 56 | fclose(output);
|
---|
| 57 | return(EX_OK);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.