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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
include<stdio.h>
02
03 double buildnumber(FILE *in_file, char ch, char *save);
04
05 main()
06 {
07
08 FILE *out_file;
09 char *save;
10 char ch = '0';
11 FILE *in_file = fopen("lab1.dat", "r");
12 out_file = fopen("lab1.out", "w");
13
14 if (in_file == NULL || out_file == NULL) {
15 printf("ERROR! cannot open file(s)\n");
16 }// End if
17 else
18 printf("Lets hope they've been opened, because they exist\n");
19
20 do
21 {
22 char c = fgetc(in_file);
23 if( feof(in_file) )
24 {
25 break ;
26 }
27 printf("%c", c);
28 }while(1);
29
30
31 buildnumber(in_file, ch, save);
32 fclose(in_file);
33 getchar();
34 }// End main
35
36 double buildnumber(FILE *in_file, char ch, char *save) {
37 double num = 0.0;
38 if (ch == '+')
39 ch = getc(in_file);
40 while (ch >= '0' && ch <= '9') {
41 num = num * 10 + ch - '0';
42 printf("%d", num);
43 ch = getc(in_file);
44 save = ch;
45
46 if (ch == '.') {
47 ch = getc(in_file);
48 while (ch >= '0' && ch <= '9')
49 num = num * .1 + ch - '0';
50 ch = getc(in_file);
51 }
52 if (ch == '+')
53 printf("%c", ch);
54
55 }// End While
56 return num;
57 }// End buildnumber
|