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
| #include <stdio.h>
#include <conio.h>
#include <string.h>
#define MINX 0
#define MAXX 1000
#define MINY 0
#define MAXY 1000
#define CHECK(X,Y) ((X)>=MINX && (X)<=MAXX && (Y)>=MINY && (Y)<=MAXY)
int main (void)
{
FILE *f,*f2;
char buf[256];
int ligne,x,y;
unsigned int coord[100];
unsigned int iPair,iCpt,incrementation;
f2=fopen("Journal.txt","a+");
if ((f=fopen("coord.txt","r"))==NULL)
{
printf("Impossible d'ouvrir le fichier\n");
return -1;
}
ligne=0;
incrementation=0;
while (fgets(buf,sizeof buf,f)!=NULL)
{
++ligne;
sscanf(buf,"%d %d",&x,&y);
coord[incrementation]=x;
incrementation++;
coord[incrementation]=y;
incrementation++;
printf("Ligne #%11d: x=%11d\ty=%11d\t%s\n",ligne,x,y);
if(CHECK(x,y))
{
for(iCpt=0;iCpt<incrementation;iCpt++)
{
// printf("%d\n",coord[iCpt]);
iPair=iCpt%2;
if(iPair==0) fprintf(f2,"x=%5d,\t",coord[iCpt]);
else
fprintf(f2,"y=%5d.\n",coord[iCpt]);
}
}
else
{
printf("depassement");
}
fclose(f);
fclose(f2);
getch();
getch();
return 0;
} |
Partager