Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8288353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:16:03+00:00 2026-06-08T12:16:03+00:00

Could you explain me why after a rewind(f) in the function recuperationdeNS, I have

  • 0

Could you explain me why after a rewind(f) in the function “recuperationdeNS”, I have a Segmentation Fault ?
The second printf in the function “recuperationdeNS” doesn’t appear. The segmentation fault stopped the program before.
I’m sure that the name of the file is ok.

Thanks

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include"procedurecommune.h"
#include"procedureGenA.h"
#include"procedureGenO.h"
void ouvrir_fic(FILE** f, char* nom,char* type)
{ 
    *f=fopen(nom,type);
    if(f==NULL)
    {
        printf("probleme lecture ou ecriture du fichier : %s\n",nom);
        exit(2);
    }
}
int recuperationdeNS(FILE* fichG)
{
    printf("aloooooooooo\n");
    int i, N;
    char chaine [2000];
    rewind(fichG);
    printf("aloooooooooo\n");
    for(i=0;i<2;i++)       // on saute les lignes de commentaires
    {
        fgets(chaine, sizeof chaine, fichG);
        printf("chaine :%s\n",chaine);
    }
    fscanf(fichG, "%d",&N); // recuperation de N
    return (N);
}

void recuperationnomfichiergena(FILE* fichG, char** NomFichierGenA, int nbligneasauter)
{       
    int i,c,iemecaractereligne;
    rewind(fichG);
    char chaine [Nmcl];
    for(i=0;i<nbligneasauter;i++)       // on saute les lignes de commentaires
    {
        fgets(chaine, sizeof chaine, fichG);
    }
    *NomFichierGenA=(char*) malloc (sizeof(char)*Nmcl);  
    fgets(chaine, sizeof chaine, fichG);
    iemecaractereligne=0;
    c=chaine[iemecaractereligne];
    while(c != '\n')
    {
        c=chaine[iemecaractereligne];
        if(c !='\n')
        {
            (*NomFichierGenA)[iemecaractereligne]=c;
        }
        iemecaractereligne++;

    }
}   


int determinationtypedegenchoisi(FILE* fichG);
int recuperationdeN(FILE* fichG);
void recuperationtabentiergenencours(FILE* fichG,int* genencours, int N);
void recuperationnomfichiergena(FILE* fichG, char ** nomfich,int nbligneasauter);

void main(int args, char **argv)
{

    FILE * fichG=NULL;  
    FILE * fichM=NULL; //fichier contenant le contexte
    FILE * fichMgenParAtt=NULL;     //fichier contenant le contexte pregeneralise par attribut
    FILE * fichGA=NULL; //fichier contenant la matrice de generalisation attribut
    FILE * fichGO=NULL;
    int** Matricegenereextraite;
    int typedegen;
    int i,nbligneMat,nbcolonneMat,nbgroupegeneralisant1,nbgroupegeneralisant2;
    char NomUniqueFichierGen[Nmcm];
    char chaine[Nmcl];
    char* NomFichGenExtraitA;
    char* NomFichGenExtraitO;
    char* NomFichGenExtraitFinale;
    char* NomFichierGenA ;
    char* NomFichierGenO;
    char* chaineNva;
    char* chaineNvo;
    int Na, No;
    int N, Ni;
    int* nbgroupegeneralisant;
    int nbgroupegeneralisantmax;
    const int nbligneenteteGparun = 5;//nombre de ligne pour acces nom fichier de gen attribut
    const int nbligneenteteGpardeux = 8;//nombre de ligne pour acces nom fichier de gen objet
    int* genencours;
    NomFichGenExtraitA=argv[3];
    NomFichGenExtraitO=argv[4];
    NomFichGenExtraitFinale=argv[5];
    chaineNva= argv[6];
    chaineNvo= argv[7];
    char dernierephrase[]="Name_of_dataset\n";
    char* nomsdesobjets;
    char** nomsdesgroupes;
    char* nomsdesattributs;
    int*** Matrice;
    //Nva=chaineNva[0]-'0';
    //Nvo=chaineNvo[0]-'0';
    /// ouverture des fichiers
    ouvrir_fic(&fichG, argv[2],"r");
    ouvrir_fic(&fichM, argv[1],"r");
    ///////////////////////////////////////////////
    //info du fichier Gen.txt
    typedegen=determinationtypedegenchoisi(fichG);
    printf("typedegen: %d\n",typedegen);
    N=recuperationdeN(fichG);
    printf("N: %d\n",N);
    allocationdynamiquetableauunedimdentier(&genencours, N);
    recuperationtabentiergenencours(fichG,genencours,N);
    ///////////////////recuperation choix de gen

    //////////////////////////////////////////////////
    //info du fichier Matrice.txt
    nblignecolonneMat(fichM,&nbligneMat,&nbcolonneMat,dernierephrase);
    printf("nbligneMat :%d, nbcolonneMat :%d\n",nbligneMat, nbcolonneMat);
    ///lecture du noms des objets et des attributs
    objetsetattributs(fichM, &nomsdesobjets,&nomsdesattributs, dernierephrase);
    printf("nomsdesO : %s\n",nomsdesobjets);
    printf("nomsdesA : %s\n",nomsdesattributs);
    //allocation dynamique
    allocationdynamiquetableautroisdimdentier(&Matrice,N,nbligneMat,nbcolonneMat);
    /// recuperation de la matrice de depart
    recuperationmatrice (fichM, Matrice[0], nbligneMat, nbcolonneMat);
    printf("\nMatrice 0:\n");
    affichageMatrice(0, nbligneMat, 0, nbcolonneMat, Matrice[0]);
    typedegen=1;



 if(typedegen==1)
    {
        //////////////////////////////////////////
        //info du fichier genO.txt
        recuperationnomfichiergena(fichG, &NomFichierGenO,nbligneenteteGpardeux);
        printf("fichier de generalisation utilise :%s\n ",NomFichierGenO);
        ouvrir_fic(&fichGO, NomFichierGenO,"r");
        No=recuperationdeNS(fichGO);
        printf("No :%d\n",No);
    }



    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:16:04+00:00Added an answer on June 8, 2026 at 12:16 pm

    Your file open check in ouvrir_fic() is faulty:

    void ouvrir_fic(FILE** f, char* nom,char* type)
    { 
        *f=fopen(nom,type);
        if(f==NULL)
        {
            printf("probleme lecture ou ecriture du fichier : %s\n",nom);
            exit(2);
        }
    }
    

    You should be checking whether *f is NULL; you’ve already assumed that f is not null when you made the assignment.

    Since the file failed to open, you have a null pointer in *f.

    I’d probably use:

    FILE *ouvrir_fic(const char *nom, const char *mode)
    { 
        FILE *fp = fopen(nom, mode);
        if (fp == NULL)
        {
            fprintf(stderr, "probleme lecture ou ecriture du fichier: %s\n", nom);
            exit(2);
        }
        return(fp);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder if anyone could explain what the default ctor does after memory allocated,
Could somebody explain is it possible to have potected, pivate methods in playfamewok's contolles
After running the code below I get this output: Eve 1200 Could anyone explain
I was hoping someone could explain what is happening i the following code taken
I was hoping someone could explain to me how eclipse automatically deploys to your
I was hoping someone could explain why my application when loaded uses varying amounts
I was wondering if someone could explain to me how to make a simple
I am wondering if someone could explain how I can utilise tags in an
I was wondering if anyone could explain what this rule is saying: <IfModule mod_rewrite.c>
this is prob pretty easy but if someone could explain the easiest way to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.