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
|
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
FILE *Ouvrir_Fichier(char *Nom) {
FILE *MonFichier;
MonFichier = fopen(Nom,"w");
if (MonFichier == NULL) {
fprintf(stderr,"Je ne trouve pas le fichier %s : ",Nom);
else {
return MonFichier;
}
}
return MonFichier;
}
void Ecrire(double x, double y , char *LeNom)
{
FILE *FichSortie;
FichSortie = fopen(Ouvrir_Fichier(LeNom), "w");
fprintf(FichSortie,"Rectangle de largeur %lf et hauteur %lf: Aire = %lf\n",x,y, aireRectangle(x, y));
fclose(FichSortie);
}
int main(int argc, char *argv[])
{
double a;
double b;
a = strtod(argv[1],(char **)NULL);
b = strtod(argv[2],(char **)NULL);
Fich=Ouvrir_Fichier(argv[3]);
Ecrire(a,b, Fich);
return 0;
}
double aireRectangle(double largeur, double hauteur)
{
return largeur * hauteur;
} |