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
   | #include <stdio.h>
#include <stdlib.h>
 
 
int main (int argc, char *argv[])
{
 
  FILE *cible;
  int rang, i=0, valeur, j=0;
 
 
  if (cible=fopen("save_int.txt","r"))
    {
 
        while (fgetc(cible)!=EOF)
	  {
	  while(fgetc(cible)!='\n')
	  j++;
	  printf("%d",j);
	  }
 
       printf("Entrez le rang de la valeur recherchee : ");
       scanf("%d",&rang);
 
       while (rang>j)
	 {
	  printf("Depassement du fichier ! \n Entrez a nouveau le rang : ");
	  scanf("%d",&rang);
	 }
 
 
       fseek(cible,0,SEEK_SET);
 
       while (!feof(cible)&&(i<rang))
 
	 {
  	  fscanf(cible,"%d",&valeur);
	  i++;
	 }
 
	printf("%d \n",valeur);
	fclose(cible);
    }  
 
  else printf("Erreur à l'ouverture du fichier ! \n");
 
  return EXIT_SUCCESS;
} | 
Partager