aboutsummaryrefslogtreecommitdiff
path: root/float2rat.c
blob: 584d637bf0d1113b0f9d9b390d119eb284efa2f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * Reads a polyhedron file on stdin with rationals and outputs 
 * an approximation in decimal floating point
 * 
 * David Bremner. bremner@cs.mcgill.ca
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <float.h>

#include "process_args.h"
#include "float2rat.h"

int main(argc,argv)
	 int argc;
	 char **argv;
{
  long int  m,n;
  int i,j;
  
  long atol();
  
  long **N;
  long **D;
  
    char  buf[BUFSIZ];
  
  process_args(argc,argv,DOCSTRING);

  while ( fgets(buf,BUFSIZ,stdin) !=NULL )
    {
      fputs(buf,stdout);
      if (strncmp(buf,"begin",5)==0) break;
    }
  

  if (scanf("%ld %ld %s",&m,&n,buf)==EOF){
    fprintf(stderr,"No begin line");
    exit(1);
  }

  printf("%ld %ld rational\n",m,n);
     
  
  for (i=0;i<m;i++)   {
    for(j=0;j<n;j++)	{
      char *p;
      char *frac;
      int k;
      
      scanf("%s",buf);
      
      if (p=index(buf,'.')){
	*p=0;
	frac=&p[1];
      } else {
	frac="";
      }


      printf("%s%s/1",buf,frac);
      for (k=0; k<strlen(frac); k++)
	putchar('0');
      
      putchar(' ');
	    
    }
    fputs("\n",stdout); 
  }

  fgets(buf,BUFSIZ,stdin);  /* clean off last line */
  
  while (fgets(buf,BUFSIZ,stdin) !=NULL )
    {
      fputs(buf,stdout);
    }
}