Les fichiers en Langage C! aidez-moi!!

wind of happiness Messages postés 12 Date d'inscription   Statut Membre Dernière intervention   -  
Char Snipeur Messages postés 9813 Date d'inscription   Statut Contributeur Dernière intervention   -
Bonjour,


j'ai un problème en ce qui concerne le tri d'un fichier texte en C!! voici ce que j'ai pu faire:



#include<stdio.h>
#include<malloc.h>
#include<conio.h>
#include<string.h>
int N;
int * In (char nom[30])
{
        printf("donner le fichier source : \n");
         gets(nom);
        FILE *a;
        int i=0;
        a=fopen("a.txt","r");
        if(a==NULL) { printf ("erreur");
                      getch ();
                      exit (0);
                      }


        fscanf(a,"%d\n",&N);
        int *t= (int*) malloc (sizeof(int)*N);
        while(!feof(a)) {
              fscanf(a,"%d\n",&t[i]);
              //printf("T[%d] = %d\n",i,t[i]);
              i++;
        }
        fclose(a);
        return t;
}
void Out(char nom[30],int *t){
     printf("donner le fichier destination : \n");
     gets(nom);
     FILE *f;
     strcat(nom,".txt");
     f=fopen(nom,"w");
     fprintf(f,"%d\n",N);
     int i;
     for(i=0;i<N;i++)
        fprintf(f,"%d\n",t[i]);
     fclose(f);
}
int * permutation(int *t){
      int i,j,x;
      for(i=0;i<N-1;i++)
      {
         for(j=i+1;j<N;j++){
              if(t[j]>t[i]){
                  x=t[j];
                  t[j]=t[i];
                  t[i]=x;
              }
         }
      }

      return t;
}

void Print(int *T){
     int i;
     for(i=0;i<N;i++)
             printf("T[%d] = %d\n",i,T[i]);
}

void Tri(char nom[30],int *t){
    t=In(nom);
    Print(t);
    t=permutation(t);
    Print(t);
    Out(nom,t);
}
int main ()
{
      int *T;
      char nomf[30];


     /*T=In(nomf);
     Print(T);

     Out(nomf,T);*/
     Tri(nomf,T);
     getch ();
     return 0;
        }





j'attends vos réponses avec impatience!
merci d'avance!
A voir également:

2 réponses

francis
 
en gros tu fais un gros copier / coller de ton code et t'attend qu'on te donne la réponse ?
0
Char Snipeur Messages postés 9813 Date d'inscription   Statut Contributeur Dernière intervention   1 299
 
Il faudrait préciser ton souci. On ne sais pas ce qu'il est sensé faire, et qu'il ne fait pas bien.
Je doute que quelqu'un prenne le temps de prendre ton code essai de comprendre ce qu'il est sensé faire (pas évident surtout si il y a un bug), mette en oeuvre un test et cherche ensuite le problème. Tu en demandes beaucoup.
0