Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
793 connectés 

  FORUM HardWare.fr
  Programmation
  Divers

  HELP !! segmentation fault... besoin d'aide

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

HELP !! segmentation fault... besoin d'aide

n°642444
shaolin38
Posté le 13-02-2004 à 22:26:21  profilanswer
 

Voila, je suis super speed...
Je dois un programme a la con pour demain qui lit des int dans un fichier , appliquent un traitement dessus et ecrit le resultat dans un autre fichier. tout ce qu'il y a de plus basique. Je lis dans le fichier avec strtok, en definissant un separateur " ", ca fonctionne pour quelques valeurs mais des que je veux en lire beaucoup cf ci dessous
J'ai un segmentation fault.
Je ne sais pas si ca vient de mon allocation memoire ou de strtok, ou meme du fait que je fait des cast un peu brutaux de char vers int, puis de int vers bool...
 
SVP, je suis GRAVE DANS LA MERDE si je resoud pas ca pour demain...  :sweat:  :sweat:  
PITIE, vous aurez toute ma gratitude. et pour de supers programmeurs ca doit etre plus qu'easy... THKS THKS !!
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
 
#ifndef _STDBOOL_H_
#define _STDBOOL_H_      
 
#define __bool_true_false_are_defined   1
 
#ifndef __cplusplus
 
#define false   0
#define true    1
 
#define bool    _Bool
#if __STDC_VERSION__ < 199901L && __GNUC__ < 3
typedef int     _Bool;
#endif
 
#endif /* !__cplusplus */
 
#endif /* !_STDBOOL_H_ */
 
 
#ifndef __Z_CST_H__
#define TYP_C_16BIT unsigned short
#define TYP_C_32BIT int
#define TYP_C_1BIT bool
#define __Z_CST_H__
#endif
 
/*Fichier   dig_prot_var.h */
//***********************************************************************
// Registres de sorties (OUT_REGISTER)
 
// entrees
bool lr_inhib;
bool cr_inhib;
bool inst_inhib;
bool sel_inhib;
 
bool VIGI;
bool GV_INHIB ;
bool NOTRIPGF;
bool REPLI_DECLT;
 
bool b_trip_or ;
bool b_other_trips ;
 
 
bool zsicr_out ;
 
bool b_DCT[4];
 
 
bool b_DIN_T ;
bool b_TCS_T ;
 
 
bool tempogf_ok;
bool pre_tripgf;
bool trip_sel;
TYP_C_32BIT tempoins_ok;
bool tempocr_ok;
bool pretrip_cr;
bool tempolr_ok;
bool pre_triplr;
bool en_tempins; //modifAD
bool pretrip_gf_zsi;
bool pretrip_cr_zsi;
bool pretrip1_sel; //modifAD
bool pretrip2_sel; //modifAD
 
 
// interne
bool b_gf_inhib ;
 
//sorties
bool tripgf ;
bool triplr ;
bool tripcr ;
bool tripinst ;
bool tripsellim ;
bool TRIPDESEQ ;
bool TRIPJAM  ;
bool TRIPDL  ;
bool TRIPSC  ;
bool tripdct ;
bool TRIP_DIN ;
bool TRIP_TCS ;
bool tripgf_indicator ;
bool triplr_indicator ;
bool tripcr_indicator ;
bool tripinst_indicator ;
bool tripsellim_indicator ;
bool TRIP_INDICATOR_DESEQ  ;
bool TRIP_INDICATOR_JAM  ;
bool TRIP_INDICATOR_DL  ;
bool TRIP_INDICATOR_SC ;
bool TRIP_INDICATOR_SDTAM_LR  ;
bool TRIP_INDICATOR_SDTAM_DESEQ ;
bool TRIP_INDICATOR_SDTAM_JAM  ;
bool TRIP_INDICATOR_SDTAM_SC  ;
bool b_TRIPA  ;
bool b_TRIPB  ;
bool TRIP_INDICATOR_DIN  ;
bool TRIP_INDICATOR_TCS  ;
bool b_RQ_SDT ;
bool b_RQ_GF_SDV ;
bool b_RQ_VIGI_SDV ;
bool b_SDTAM_LR ;
bool b_SDTAM_SC ;
bool b_SDTAM_DESEQ ;
bool b_SDTAM_JAM ;                  
 
 
void startup0()
{
  // Etat initial : Toutes entrées et sorties à 0
 
}
 
 
 
void output_logic(void)
{
 
/*[traitement des données : combinaisons combinatoires des entrees...]*/
 
}
 
 
int main()
{
 
  FILE *pstim;
  FILE *pref;
 
  char line_in[50],line_out[50];
 
  char *mot;
  bool not_used;
  bool inputs[50];  
  bool outputs[50];  
 
  pstim = fopen("stim.txt","r" );
  pref = fopen("ref.txt","w" );
 
 
  if (pstim != NULL && pref != NULL)
  {
 
    printf("DISTRIB_BLOC Modele C\n" );
 
    fputs("# DISTRIB_BLOC_OUTPUTS(1:36)\n",pref);
    fputs("#\n",pref);
 
    while (fgets(line_in,50,pstim) != NULL)  
    {
      mot=strtok(line_in," " );
      if (mot !=NULL || mot[0]!='#')
      {
        for(i=1; i<=37;i++)
        {
          mot=strtok(NULL," " );
          inputs[i]=atoi(mot);  
        }
 
        lr_inhib                  = inputs[1];
        cr_inhib                  = inputs[2];
        inst_inhib                = inputs[3];
        sel_inhib                 = inputs[4];
        not_used                  = inputs[5];
        not_used                  = inputs[6];
        not_used                  = inputs[7];
        not_used                  = inputs[8];
        VIGI                      = inputs[9];
        GV_INHIB                  = inputs[10];
        NOTRIPGF                  = inputs[11];
        REPLI_DECLT               = inputs[12];
        b_trip_or                 = inputs[13];
        b_other_trips             = inputs[14];
        not_used                  = inputs[15];
        zsicr_out                 = inputs[16];
        not_used                  = inputs[17];
        not_used                  = inputs[18];
        b_DCT[0]                  = inputs[19];
        b_DCT[1]                  = inputs[20];
        b_DCT[2]                  = inputs[21];
        b_DCT[3]                  = inputs[22];
        b_DIN_T                   = inputs[23];
        b_TCS_T                   = inputs[24];
        tempogf_ok                = inputs[25];
        pre_tripgf                = inputs[26];
        trip_sel                  = inputs[27];
        tempoins                  = inputs[28];
        tempocr_ok                = inputs[29];
        pretrip_cr                = inputs[30];
        tempolr_ok                = inputs[31];
        pre_triplr                = inputs[32];
        en_tempins                = inputs[33];
        pretrip_gf_zsi            = inputs[34];
        pretrip_cr_zsi            = inputs[35];
        pretrip1_sel              = inputs[36];
        pretrip2_sel              = inputs[37];
 
        // traitement des entrees
        output_logic();
 
        outputs[1] =      tripgf ;
        outputs[2] =      triplr ;
        outputs[3] =      tripcr ;
        outputs[4] =      tripinst ;
        outputs[5] =      tripsellim ;
        outputs[6] =      TRIPDESEQ ;
        outputs[7] =      TRIPJAM  ;
        outputs[8] =      TRIPDL  ;
        outputs[9] =      TRIPSC  ;
        outputs[10] =     tripdct ;
        outputs[11] =     TRIP_DIN ;
        outputs[12] =     TRIP_TCS ;
        outputs[13] =     tripgf_indicator ;
        outputs[14] =     triplr_indicator ;
        outputs[15] =     tripcr_indicator ;
        outputs[16] =     tripinst_indicator ;
        outputs[17] =     tripsellim_indicator ;
        outputs[18] =     TRIP_INDICATOR_DESEQ  ;
        outputs[19] =     TRIP_INDICATOR_JAM  ;
        outputs[20] =     TRIP_INDICATOR_DL  ;
        outputs[21] =     TRIP_INDICATOR_SC ;
        outputs[22] =     TRIP_INDICATOR_SDTAM_LR  ;
        outputs[23] =     TRIP_INDICATOR_SDTAM_DESEQ ;
        outputs[24] =     TRIP_INDICATOR_SDTAM_JAM  ;
        outputs[25] =     TRIP_INDICATOR_SDTAM_SC  ;
        outputs[26] =     b_TRIPA  ;
        outputs[27] =     b_TRIPB  ;
        outputs[28] =     TRIP_INDICATOR_DIN  ;
        outputs[29] =     TRIP_INDICATOR_TCS  ;
        outputs[30] =     b_RQ_SDT ;
        outputs[31] =     b_RQ_GF_SDV ;
        outputs[32] =     b_RQ_VIGI_SDV ;
        outputs[33] =     b_SDTAM_LR ;
        outputs[34] =     b_SDTAM_SC ;
        outputs[35] =     b_SDTAM_DESEQ ;
        outputs[36] =     b_SDTAM_JAM ;                
 
        for(i=1; i<=36;i++)
        {
          sprintf(line_out,"%d ",outputs(i));
        }
 
        fputs(line_out,pref);
      }
 
    }
       
    fclose(pstim);
    fclose(pref);
    printf("Termine\n" );
 
  }
  else
  {
    printf("Probleme d'ouverture de stim.txt ou d'ecriture de ref.txt\n" );
  }
 
}

mood
Publicité
Posté le 13-02-2004 à 22:26:21  profilanswer
 


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Divers

  HELP !! segmentation fault... besoin d'aide

 

Sujets relatifs
HELP !! segmentation fault... besoin d'aidesql help
[CSS] bug sous I.E., aide :)aide header()
[J2EE] Besoin d'une introduction aux technologies web du momenthelp needed: cryptage sur une suite de mots
Plus de sujets relatifs à : HELP !! segmentation fault... besoin d'aide


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR