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
| #include <stdio.h>
#include <conio.h>
#include <alloc.h>
#include <stdlib.h>
#include <C:\COURS\TC\EXEMPLE\EXEMPLE.H>
/***********************/
/* Fonction nombre de valeur */
/*********/*************/
int valeur ()
{
int a, x0, y0 ;
printf ("Nombre de valeur à considérer > 0 : ") ;
x0 = wherex () ; y0 = wherey () ;
do
{
gotoxy(x0,y0) ;
clreol () ;
scanf ("%d", &a) ;
}while(a==0 || a<0) ;
return (a) ;
}
/*****************/
/* Saisie des données */
/*****************/
void saisie (float *tableau, int n)
{
int x1, y1, cpt ;
float x ;
clrscr () ;
printf ("Saisie des données\n") ;
printf ("ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ\n\n") ;
cpt = 0 ;
printf("\nValeur [%2d] : ", cpt) ;
x1 = wherex() ; y1 = wherey() ;
for (cpt=1 ; cpt<n ; cpt++)
{
printf("\nValeur [%2d] : ", cpt) ;
}
for (cpt=0 ; cpt<n ; cpt++)
{
gotoxy (x1,y1) ;
scanf ("%f", &x) ;
tableau[cpt] = x ;
y1++ ;
}
}
/*****************/
/* Affichage du menu */
/*****************/
int menu ()
{
int b, x0, y0 ;
clrscr () ;
printf("Menu\n") ;
printf("ÍÍÍÍ\n\n") ;
printf("1 --> Edition des valeurs\n") ;
printf("2 --> Creation d'un fichier backup\n") ;
printf("3 --> Lecture d'un fichier backup\n") ;
printf("0 --> Quitter le programme\n\n") ;
printf("\nFaites votre choix --> ") ;
x0 = wherex() ; y0 = wherey () ;
do
{
gotoxy(x0,y0);
clreol ();
scanf("%d", &b);
}while(b<0 || b>3) ;
return (b) ;
}
/******************/
/* Edition des données */
/******************/
void edition (float *tableau, int n)
{
int cpt ;
clrscr () ;
printf ("Edition des données\n") ;
printf ("ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ\n") ;
for (cpt=0 ; cpt<n ; cpt++)
{
printf ("\nLa valeur [%2d] : %.3f", cpt, *(tableau+cpt) ) ;
}
getch () ;
}
/*****************/
/* Création du fichier */
/*****************/
void ecriture (float *tableau, int n)
{
char nom[50] ;
FILE *ecriture ;
clrscr () ;
fflush (stdin) ;
printf("Nom du fichier : ") ;
gets(nom) ;
ecriture = fopen(nom, "wb") ;
fwrite (&n,sizeof(int),1,ecriture) ;
fwrite (tableau, sizeof(float), n, ecriture) ;
fclose(ecriture) ;
}
/****************/
/* Lecture du fichier */
/****************/
void lecture (float *tableau, int n)
{
char nom[50] ;
int cpt ;
FILE *lecture ;
clrscr () ;
fflush (stdin) ;
printf("Nom du fichier à lire : ") ;
gets(nom) ;
lecture = fopen(nom, "rb") ;
fread (&n,sizeof(int),1,lecture) ;
tableau = (float*)realloc(tableau, n*sizeof(float)) ;
/* C'est ici qu'il y a un problème */
fread (tableau, sizeof(float), n, lecture) ;
fclose(lecture) ;
} |
Partager