source: liacs/da/opdr2b/read.cc@ 95

Last change on this file since 95 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
Line 
1/* Author : Rick van der Zwet
2 * S-number : 0433373
3 * Version : $Id: read.cc 390 2007-12-20 23:24:34Z rick $
4 * Copyright : FreeBSD Licence
5 */
6#include <stdio.h>
7#include <errno.h>
8#include <stdlib.h>
9#include <sysexits.h>
10
11
12//XXX: File are only checked at creation time, not during execution
13int main (int argc, char ** argv)
14{
15 FILE * input;
16 FILE * output;
17
18 if (argc < 2)
19 {
20 fprintf(stderr, "Usage: %s <infile> [<outfile>]\n",argv[0]);
21 return(EX_USAGE);
22 }
23
24 input = fopen(argv[1], "r");
25 if (input == NULL)
26 {
27 fprintf(stderr,"Error: Unable to use `%s', errno: %i\n",
28 argv[1], errno);
29 return(EX_NOINPUT);
30 }
31
32 if (argc == 3)
33 {
34 output = fopen(argv[2], "w");
35 if (output == NULL)
36 {
37 fprintf(stderr,"Error: Unable to use `%s', errno: %i\n",
38 argv[2], errno);
39 return(EX_CANTCREAT);
40 }
41 }
42 else
43 {
44 output = stdout;
45 }
46
47
48 int number = 0;
49 int row = 0;
50 while ((number = getc(input)) != EOF)
51 {
52 fprintf(output,"%03i ", number);
53 row++;
54 if ( row == 20 )
55 {
56 printf("\n");
57 row = 0;
58 }
59 }
60
61 fprintf(output,"\n");
62 fclose(input);
63 fclose(output);
64 return(EX_OK);
65}
66
Note: See TracBrowser for help on using the repository browser.