Merci :)
Version imprimable
Merci :)
Code:
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 // excercice.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <stdlib.h> #include <stdio.h> void do_heading(char *filename); int line, page; int main ( int argv, char *argc[] ) { char buffer[256]; FILE *fp; if( argv < 2 ) { fprintf(stderr, "\nLa syntaxe correcte est: " ); fprintf(stderr, "\n\nPRINT_IT nomfichier.ext\n" ); exit(1); } if (( fp = fopen( argc[1], "r" )) == NULL ) fprintf( stderr, "Erreur d'ouverture du fichier, %s!", argc[1]); exit(1); } page = 0; line= 1; do_heading( argc[1]); while ( fgets(buffer, 256, fp ) != NULL ) { if( line % 55 == 0 ) do_heading( argc[1] ); fprintf( stdprn, "%4d:\t%s", line++, buffer ); { fprintf( stdprn, "\f" ); fclose(fp); return 0; } void do_heading( char *filename ) { page++; if (page > 1) fprintf( stdprn, "\f" ); fprintf (stdprn, "Page: %d, %s\n\n", page, filename ); }
:) encore un problème qui pourait me corriger svpCitation:
------ Build started: Project: excercice, Configuration: Debug Win32 ------
Compiling...
excercice.cpp
c:\documents and settings\administrateur\mes documents\c++\excercice\excercice\excercice\excercice.cpp(28) : warning C4996: 'fopen' was declared deprecated
c:\program files\microsoft visual studio 8\vc\include\stdio.h(234) : see declaration of 'fopen'
Message: 'This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
c:\documents and settings\administrateur\mes documents\c++\excercice\excercice\excercice\excercice.cpp(15) : warning C4101: 'buffer' : unreferenced local variable
c:\documents and settings\administrateur\mes documents\c++\excercice\excercice\excercice\excercice.cpp(33) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\administrateur\mes documents\c++\excercice\excercice\excercice\excercice.cpp(33) : error C2086: 'int page' : redefinition
c:\documents and settings\administrateur\mes documents\c++\excercice\excercice\excercice\excercice.cpp(11) : see declaration of 'page'
c:\documents and settings\administrateur\mes documents\c++\excercice\excercice\excercice\excercice.cpp(34) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\administrateur\mes documents\c++\excercice\excercice\excercice\excercice.cpp(34) : error C2086: 'int line' : redefinition
c:\documents and settings\administrateur\mes documents\c++\excercice\excercice\excercice\excercice.cpp(11) : see declaration of 'line'
c:\documents and settings\administrateur\mes documents\c++\excercice\excercice\excercice\excercice.cpp(35) : error C2065: 'argc' : undeclared identifier
c:\documents and settings\administrateur\mes documents\c++\excercice\excercice\excercice\excercice.cpp(35) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\administrateur\mes documents\c++\excercice\excercice\excercice\excercice.cpp(35) : error C2365: 'do_heading' : redefinition; previous definition was 'function'
c:\documents and settings\administrateur\mes documents\c++\excercice\excercice\excercice\excercice.cpp(9) : see declaration of 'do_heading'
c:\documents and settings\administrateur\mes documents\c++\excercice\excercice\excercice\excercice.cpp(35) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Build log was saved at "file://c:\Documents and Settings\Administrateur\Mes documents\C++\excercice\excercice\excercice\Debug\BuildLog.htm"
excercice - 8 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
C'est bien de Peter Aitken & Bradley L.Jones :roll:Citation:
Envoyé par Gnux
Mes remarques et corrections (-ed-) dans le fichier resultat ! :Citation:
Envoyé par zero_cool
Code:
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169 Page: 1, main.c 1: #define DBG 0 2: #define ARG 1 3: #include "frmwrk/inc/main.h" 4: /* ------------------------------------------------------------------------------------------- */ 5: //#line 1 6: // excercice.cpp : Defines the entry point for the console application. 7: /* -ed- ce .cpp est suspect. Il faudrait un .c */ 8: 9: // 10: 11: /* -ed- 12: #include "stdafx.h" 13: 14: inconnu et inutile 15: */ 16: #include <stdlib.h> 17: #include <stdio.h> 18: 19: 20: /* -ed- gestion de la sortie (imprimante, fichier...) */ 21: #if 0 22: /* DOS/Windows */ 23: #define PRINTER "prn" 24: #else 25: /* debug */ 26: #define PRINTER "data.txt" 27: #endif 28: 29: 30: /* -ed- 31: int line, page; 32: 33: pourquoi des globales ? 34: 35: Provisoirement rendues 'static' car non exportees. 36: 37: Mais une reconception d'impose pour les supprimmer. 38: (structure contexte, par exemple) 39: 40: static int line, page; 41: */ 42: 43: struct info 44: { 45: int page; 46: }; 47: 48: 49: /* -ed- 50: void do_heading(char *filename); 51: 52: inutile si on utilise le principe 'definir avant d'utiliser 53: Fonction deplacee et rendue 'static' car non exportee. 54: */ Page: 2, main.c 55: static void do_heading(FILE *fp_prn, char *filename, struct info *p_info ) 56: { 57: p_info->page++; 58: 59: if (p_info->page > 1) 60: { 61: /* -ed- 62: fprintf( stdprn, "\f" ); 63: 64: pas de stdprn en C standard. C'est une extension de Borland. 65: 66: Remplace par un context flux passe en parametre. 67: */ 68: fprintf( fp_prn, "\f" ); 69: } 70: 71: fprintf (fp_prn, "Page: %d, %s\n\n", p_info->page, filename ); 72: 73: } 74: 75: /* -ed- 76: int main (int argv, char *argc[] ) 77: 78: On est plus habitue a un nommage plus conventionnel 79: (c pour 'count' et v pour 'vector') 80: */ 81: int main (int argc, char *argv[] ) 82: { 83: char buffer[256]; 84: FILE *fp; 85: 86: if ( argc < 2 ) 87: { 88: 89: fprintf(stderr, "\nLa syntaxe correcte est: " ); 90: fprintf(stderr, "\n\nPRINT_IT nomfichier.ext\n" ); 91: /* -ed- 92: exit(1); 93: 94: la valeur 'defaut' portable est EXIT_FAILURE 95: */ 96: exit(EXIT_FAILURE); 97: } 98: 99: if (( fp = fopen( argv[1], "r" )) == NULL ) 100: /* -ed- manquait une { */ 101: { 102: fprintf( stderr, "Erreur d'ouverture du fichier, %s!", argv[1]); 103: exit(EXIT_FAILURE); 104: } 105: 106: { 107: /* -ed- reconception des donnees */ 108: struct info info = 109: { Page: 3, main.c 110: 0 111: }; 112: int line = 1; 113: 114: /* -ed- ajoute gestion du flux imprimante */ 115: FILE *fp_prn = fopen (PRINTER, "w"); 116: 117: if (fp_prn != NULL) 118: { 119: do_heading (fp_prn, argv[1], &info); 120: /* -ed- 121: while (fgets(buffer, 256, fp ) != NULL ) 122: 123: laisser le compilateur faire les calculs. C'est plus sur. 124: */ 125: while (fgets(buffer, sizeof buffer, fp ) != NULL) 126: { 127: 128: if (line % 55 == 0) 129: /* -ed- 130: ce '55' est une donnee applicative 131: (nombre max de lignes par pages, je suppose). 132: 133: Elle devrait au minimum etre definie avec 134: une constante symbolique au lieu d'etre cablee 135: 'en dur' au milieu du code.... 136: 137: (pour moi, ce serait une variable de configuration) 138: */ 139: { 140: do_heading(fp_prn, argv[1] , &info); 141: } 142: /* -ed- 143: fprintf (fp_prn, "%4d:\t%s", line++, buffer); 144: 145: Ne pas placer d'operateur unaire dans un appel de fonction. LE comportement est indefini. 146: */ 147: fprintf (fp_prn, "%4d:\t%s", line, buffer); 148: line++; 149: 150: /* -ed- manquait une } */ 151: } 152: fprintf (fp_prn, "\f" ); 153: fclose(fp); 154: fclose (fp_prn), fp_prn = NULL; 155: } 156: else 157: { 158: perror(PRINTER); 159: } 160: } 161: return 0; 162: }