예제 #1
0
파일: lagrange.c 프로젝트: erickedji/zinal
void
ouvrir_fichier(void)
{
    int choix,nb_champs; // nb_champs est le nombre de champs convertis par fscanf
    double x; // utilisé pour vérifier si les données sont au format attendu

    donnees = open_r(quel_nom(),0);

    if(!donnees)
    {
        if(!OF_abandon) // l'utilisateur n'as pas abandonné, c'est donc une erreur système
        {
            erreur("Une erreur système est survenue lors de l\'ouverture du ficher");
            info("Désolé pour le désagrément");
            info("Description système");
            perror("");
        }

        menu();
        return; // plus rien à faire ici
    }

    // A ce stade, le fichier est correctement ouvert
    // Basic sanity test, profitons-en pour calculer le nombre de points
    n = 0;
    nb_champs = 2;
    while(!feof(donnees) && nb_champs == 2)
    {
        nb_champs = fscanf(donnees,"%lf\t%lf\n", &x, &x);
        n ++;
    }

    if(!feof(donnees)) // on n'est toujours pas à la fin du fichier, il est donc mal formatté
    {
        info("Le fichier ne contient pas des données au format attendu");
        invite("Réessayer? (0 = non, 1 = oui):");
        scanf("%d",&choix);
        vider_stdin();

        if(choix == 0)
            menu();
        else
            ouvrir_fichier();

        return; // plus rien a faire ici, sortir
    }

    // Tout est normal, on a terminé    
    rewind(donnees); //Comme sur le magnétophone! ce sacré Ritchie!
}
예제 #2
0
파일: lagrange.c 프로젝트: erickedji/zinal
void du_fichier(void)
{
    int i,choix;

    info("Lecture des valeurs x[i] et y[i] à partir d'un fichier:");
    info("Le fichier doit contenir un point par ligne comme suit:\n");
    info("\tx[i]\ty[i]\n\t\tx[i+1]\ty[i+1]\n\t\t...");

    ouvrir_fichier();

    x = MALLOC(double,n);
    y = MALLOC(double,n);

    if((x == NULL) || (y == NULL))
    {
        erreur("Impossible d\'allouer la mémoire pour x et y (dans du_fichier())");
        perror("Description système de l\'erreur");
        menu();
        return;
    }

    for(i = 0; i < n; i ++)
    {
        fscanf(donnees,"%lf\t%lf\n",x+i,y+i);
    }
    fclose(donnees);

    if(verifier() == 0)
    {
        erreur("Les valeurs des xi ne sont pas deux a deux distinctes.");
        info("Vous pouvez :\n\t1 - Recommencer\n\t2 - Abandonner");
        invite("Votre choix :");
        scanf("%d",&choix);
        vider_stdin();

        if(choix == 1)
        {
            du_fichier();
            return; //plus rien à faire ici
        } else { // il abandonne
            menu();
            return;
        }
    }

    menu();
}
예제 #3
0
int		main(int ac, char **av)
{
	char **map;

	map = 0;
	if (ac >= 2)
		map = ouvrir_fichier(ac - 1, av);
	else
	{
		map = (char**)malloc(sizeof(char*) * 2);
		map[0] = 0;
		ft_argtostr(map);
		map[1] = 0;
	}
	resoudre(map);
	free(*map);
	return (0);
}
예제 #4
0
int main(int argc, char ** argv){
  struct timeval start, end;
  Liste * fichiers = fichiers_reguliers(SHAKESPEARE_DIR);
  Liste * mots;
  char * fichier;
  TrieHybride * t = NULL;
  int i,fd,fd2,arg_fusion,res;
  double res_d;
  char buff[128];
  pthread_t tid[NB_THREADS];
  pthread_attr_t attr; 
  briandais_t * br;

  /****************************************************************************
                      BENCHMARK INSERTION NON MULTITHREADE
  ****************************************************************************/
  printf("Insertion de toutes les pieces de Shakespeare \t\t: En cours ...");
  fflush(stdout);
  temps(&start);
  while((fichier=supprimer_debut(fichiers))){
    t=lire_fichier_th(fichier,t);
    free(fichier);
  }
  temps(&end);
  afficher_res(start,end);
  destroy_liste(fichiers);

  /****************************************************************************
                          SUPPRESSION MOTS HAMLET
  ****************************************************************************/
  printf("Suppression des mots de la piece \"Hamlet\" \t\t: En cours ...");  
  fflush(stdout);

  fd=ouvrir_fichier(SHAKESPEARE_DIR"hamlet.txt");
  if(fd<0){
    perror("ouverture fichier");
    exit(EXIT_FAILURE);
  }

  temps(&start);
  while(mot_suivant(fd,buff)>0){
    t=supprimer(t,buff);
  }
  temps(&end);
  afficher_res(start,end);

  if(close(fd)==-1){
    perror("close");
    exit(EXIT_FAILURE);
  }

  /****************************************************************************
                         RECHERCHE ALL'S WELL & HAMLET
  ****************************************************************************/
  printf("Recherche des mots de All's Well et Hamlet \t\t: En cours ...");  
  fflush(stdout);

  fd=ouvrir_fichier(SHAKESPEARE_DIR"hamlet.txt");
  if(fd<0){
    perror("ouverture fichier");
    exit(EXIT_FAILURE);
  }

  fd2=ouvrir_fichier(SHAKESPEARE_DIR"allswell.txt");
  if(fd2<0){
    perror("ouverture fichier");
    exit(EXIT_FAILURE);
  }

  temps(&start);
  while(mot_suivant(fd,buff)>0){
    recherche_trie_hybride(t,buff);
  } 
  while(mot_suivant(fd2,buff)>0){
    recherche_trie_hybride(t,buff);
  }
  temps(&end);

  afficher_res(start,end);
  if(close(fd)==-1){
    perror("close");
    exit(EXIT_FAILURE);
  } 

  if(close(fd2)==-1){
    perror("close");
    exit(EXIT_FAILURE);
  }

  /****************************************************************************
                        DESTRUCTION TRIE HYBRIDE
  ****************************************************************************/
  printf("Destruction du trie hybride \t\t\t\t: En cours ...");  
  fflush(stdout);

  temps(&start);
  free_trie_hybride(t);
  temps(&end);

  afficher_res(start,end);

  /****************************************************************************
                       CREATION SHAKESPEARE MULTITHREADE
  ****************************************************************************/
  fics=fichiers_reguliers(SHAKESPEARE_DIR);
  tries=creer_liste();
  sem_init(&sem,1,0);
  arg_fusion=fics->taille;  
  pthread_attr_init(&attr);
  pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);

  printf("Insertion multithreade des oeuvres de Shakespeare\t: En cours ...");  
  fflush(stdout);


  temps(&start);
  pthread_mutex_lock(&mutex_fics);
  for(i=0;i<NB_THREADS-1;i++){
    if(pthread_create(&(tid[i]),&attr,creation_trie_thread,NULL)==-1){
      perror("pthread_create");
      exit(EXIT_FAILURE);
    }
  }
  
  if(pthread_create(&(tid[NB_THREADS-1]),&attr,fusion_thread,&arg_fusion)==-1){
    perror("pthread_create");
    exit(EXIT_FAILURE);
  }

  pthread_cond_wait(&cond,&mutex_fics);
  temps(&end);

  afficher_res(start,end);

  destroy_liste(fics);
  t=supprimer_debut(tries);
  destroy_liste(tries);

 /****************************************************************************
                                COMPTAGE MOTS
  ****************************************************************************/
  printf("Comptage des mots \t\t\t\t\t: En cours ...");
  fflush(stdout);

  temps(&start);
  res=comptage_mots(t);
  temps(&end);
  afficher_res(start,end);
  printf("\t\t\t\t\t\t\t  %d\n",res);

  /****************************************************************************
                              POINTEURS VERS NULL
  ****************************************************************************/ 
  printf("Comptage des pointeurs vers NULL\t\t\t: En cours ...");
  fflush(stdout);

  temps(&start);
  res=comptage_nil(t);
  temps(&end);
  afficher_res(start,end);
  printf("\t\t\t\t\t\t\t  %d\n",res);

  /****************************************************************************
                 CREATION ET DESTRUCTION DE LA LISTE DES MOTS
  ****************************************************************************/ 
  printf("Creation et destruction de la liste des mots\t\t: En cours ...");
  fflush(stdout);

  temps(&start);
  mots=liste_mots(t);
  while(mots->taille!=0){
    char * tmp=supprimer_debut(mots);
    free(tmp);
  }
  free(mots);
  temps(&end);
  afficher_res(start,end);

  /****************************************************************************
                                   HAUTEUR
  ****************************************************************************/
  printf("Calcul de la hauteur \t\t\t\t\t: En cours ...");
  fflush(stdout);
  temps(&start);
  res=hauteur(t);
  temps(&end);
  afficher_res(start,end);
  printf("\t\t\t\t\t\t\t  %d\n",res);


  /****************************************************************************
                                 EQUILIBRAGE
  ****************************************************************************/
  printf("Equilibrage du trie\t\t\t\t\t: En cours ...");
  fflush(stdout);
  temps(&start);
  t=equilibrer(t);
  temps(&end);
  afficher_res(start,end);

  /****************************************************************************
                              RECALCUL HAUTEUR
  ****************************************************************************/
  printf("Recalcul de la hauteur \t\t\t\t\t: En cours ...");
  fflush(stdout);
  temps(&start);
  res=hauteur(t);
  temps(&end);
  afficher_res(start,end);
  printf("\t\t\t\t\t\t\t  %d\n",res);

  /****************************************************************************
                             PROFONDEUR MOYENNE
  ****************************************************************************/
  printf("Profondeur Moyenne\t\t\t\t\t: En cours ...");
  fflush(stdout);
  temps(&start);
  res_d=profondeur_moyenne(t);
  temps(&end);
  afficher_res(start,end);
  printf("\t\t\t\t\t\t\t  %f\n",res_d);

  /****************************************************************************
                          CONVERSION VERS BRIANDAIS
  ****************************************************************************/
  printf("Conversion vers arbre de la briandais\t\t\t: En cours ...");
  fflush(stdout);
  temps(&start);
  br=conversion(t);
  temps(&end);
  afficher_res(start,end);
  destroy_briandais(&br);

  /****************************************************************************
                        INSERTION D'UN MOT INEXISTANT
  ****************************************************************************/
  printf("Insertion d'un mot inexistant(anticonstitutionnellement): En cours ...");
  fflush(stdout);
  temps(&start);
  t=ajouter_trie_hybride("anticonstitutionnellement",t);
  temps(&end);
  afficher_res(start,end);
 
 /****************************************************************************
                        INSERTION D'UN MOT INEXISTANT
  ****************************************************************************/
  printf("Usage memoire (en octets)\t\t\t\t: En cours ...");
  fflush(stdout);
  temps(&start);
  res=usage_memoire(t);
  temps(&end);
  afficher_res(start,end);
  printf("\t\t\t\t\t\t\t  %d\n",res);

  free_trie_hybride(t);
  return EXIT_SUCCESS;
}