-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAMA.c
87 lines (66 loc) · 2.72 KB
/
AMA.c
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
87
//---------------------------------------------------------------------------| AMA von Dietmar SCHRAUSSER 2010
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <time.h>
void _profil();
void _kopf();
void main(int argc, char *argv[])
{
FILE *inStream, *in1Stream, *outStream;
int n_1=0, n_2=0, nk_1=-1, nk_2=-1, k_1, k_2, iLauf, jLauf;
char dat1[20], dat2[20];
double dat3;
if (argc != 5 ){ printf("\n> check arguments\n"); _profil();}
if(fopen(argv[1],"r")==0){ printf("\n> check file %s\n", argv[1]); _profil();}
if(fopen(argv[2],"r")==0){ printf("\n> check file %s\n", argv[2]); _profil();}
inStream = fopen( argv[1], "r" ); do { if(fgetc(inStream)=='\n') n_1++;} while (feof (inStream) == 0); fclose( inStream );
inStream = fopen( argv[1], "r" ); do { fscanf(inStream, "%s", dat1); nk_1++;} while (feof (inStream) == 0); fclose( inStream );
inStream = fopen( argv[2], "r" ); do { if(fgetc(inStream)=='\n') n_2++;} while (feof (inStream) == 0); fclose( inStream );
inStream = fopen( argv[2], "r" ); do { fscanf(inStream, "%s", dat1); nk_2++;} while (feof (inStream) == 0); fclose( inStream );
k_1=nk_1/n_1;
k_2=nk_2/n_2;
if (k_1 != k_2) { printf("\n> k1 <> k2\n"); _profil();}
if (n_1 != n_2) { printf("\n> n1 <> n2\n"); _profil();}
_kopf();
inStream = fopen( argv[1], "r" );
in1Stream = fopen( argv[2], "r" );
outStream = fopen( argv[3], "w" );
for(iLauf=1; iLauf<= n_1; iLauf++)
{
for(jLauf=1; jLauf<= k_1; jLauf++)
{
fscanf(inStream,"%s",dat1); fscanf(in1Stream,"%s",dat2);
if(atoi(argv[4])==0) dat3=atof(dat1) + atof(dat2);
if(atoi(argv[4])==1) dat3=atof(dat1) - atof(dat2);
fprintf(outStream,"%.3f",dat3);
if(jLauf < k_1)fprintf(outStream," ");
}
fprintf(outStream,"\n");
}
fclose( inStream );
fclose( in1Stream );
fclose( outStream );
}
void _profil()
{
printf("----------------------------------------------\n");
printf("Usage: AMA [matrix1] [matrix2] [output] [mode]\n");
printf(" [matrix1] ...... Matrix Datei 1\n");
printf(" [matrix2] ...... Matrix Datei 2\n");
printf(" [output] ....... Matrix Ausgabe Datei\n");
printf(" [mode] ......... (0):+ (1):-\n");
printf("----------------------------------------------\n");
printf("AMA by Dietmar Schrausser\n");
printf("compiled on %s @ %s\n", __DATE__, __TIME__);
//getch();
exit(0);
}
void _kopf()
{
printf("\nAMA by Dietmar Schrausser\n");
printf("compiled on %s @ %s\n", __DATE__, __TIME__);
printf("computing AMA:\n");
}