IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

aide sur ce le probleme de segmentation fault


Sujet :

C++

  1. #1
    Membre du Club
    Inscrit en
    Août 2007
    Messages
    88
    Détails du profil
    Informations forums :
    Inscription : Août 2007
    Messages : 88
    Points : 44
    Points
    44
    Par défaut aide sur ce le probleme de segmentation fault
    mon programme il compile et lorsque je l'execute il m'affiche segmentation fault un aide s'il vous plai

    voici le code

    Code C++ : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    #include <iostream>
    #include <fstream>
    #include <string>
     
    using namespace std;
     
    #define FILTER_SIZE 10
    #define NUM_HASHES 7
    #define WORD_BUF_SIZE 32
     
    #define FILTER_SIZE_BYTES (1 << (FILTER_SIZE - 3))
    #define FILTER_BITMASK ((1 << FILTER_SIZE) - 1)
     
    /* function de hashage */
    unsigned int RSHash (unsigned char const *, size_t);
    unsigned int DJBHash (unsigned char const *, size_t);
    unsigned int FNVHash (unsigned char const *, size_t);
    unsigned int JSHash (unsigned char const *, size_t);
    unsigned int PJWHash (unsigned char const *, size_t);
    unsigned int SDBMHash(unsigned char const *, size_t);
    unsigned int DEKHash (unsigned char const *, size_t);
     
    /* fonction de help */
    void Verifir_Sys(unsigned char[], char const *file, char const *file1);
    void insert_word(unsigned char[], string word);
    int in_dict(unsigned const char[], string word);
    void get_hashes(unsigned int[], string const & word);
     
    int main(int argc, char *argv[])
    {
    	unsigned char filter[FILTER_SIZE_BYTES];
    	if(argc < 3){
    		cout<<"le nombre de parametre a fournir au fonction est insuffisant"<<endl;
    	}
    	else
    		Verifir_Sys(filter,argv[1],argv[2]);
    	return 1;
    }
     
    void Verifir_Sys(unsigned char filter[], char const *filename, char const *filename1)
    {
    	string AdrePortSour;
    	string AdrePortDest;
    	int test;
    	fstream fichier(filename);
    	fstream fichiersysAck(filename1);
    	if ( !fichier ) { // si le fichier n'est pas trouvé
    		cout << "fichier inexistant";
    	} else { // sinon
    		bool continuer = true; // indicateur de fin de fichier
    		while( continuer ) {
    			string ch; // chaine contenant une ligne du fichier
    			fichier >> ch; // ranger une ligne dans ch
    			if ( ch != "" ){
    				if(ch=="S"){ //si la ligne n'est pas vide faire
    					fichier >> ch;
    					AdrePortSour=AdrePortSour+ch;
    					fichier >> ch;
    					AdrePortSour=AdrePortSour+" "+ch;
    					cout<<AdrePortSour<<endl;
    					AdrePortSour="";
    					insert_word(filter,AdrePortSour);
    				}
    				if(ch=="SA"){ //si la ligne n'est pas vide faire
    					fichier >> ch;
    					fichier >> ch;
    					fichier >> ch;
    					fichier >> ch;
    					AdrePortDest=AdrePortDest+ch;
    					fichier >> ch;
    					AdrePortDest=AdrePortDest+" "+ch;
    					cout<<AdrePortDest<<endl;
    					AdrePortDest="";
    					test=in_dict(filter,AdrePortDest);
    					if(test==0)
    						fichiersysAck <<AdrePortDest;
    				}
     
    			}
    			else // sinon
    				continuer = false; // sortir de la boucle de lecture
    		}//while
    	}
    }
     
     
     
    void insert_word(unsigned char filter[], string str)
    {
    	unsigned int hash[NUM_HASHES];
    	int i;
     
    	get_hashes(hash, str);
     
    	for (i = 0; i < NUM_HASHES; i++) {
    		hash[i] = (hash[i] >> FILTER_SIZE) ^ (hash[i] & FILTER_BITMASK);
    		filter[hash[i] >> 3] |= 1 << (hash[i] & 7);
    	}
    }
     
     
    int in_dict(unsigned char const filter[], string str)
    {
    	unsigned int hash[NUM_HASHES];
    	int i;
     
    	get_hashes(hash, str);
     
    	for (i = 0; i < NUM_HASHES; i++) {
    		hash[i] = (hash[i] >> FILTER_SIZE) ^ (hash[i] & FILTER_BITMASK);
    		if (!(filter[hash[i] >> 3] & (1 << (hash[i] & 7))))
    			return 0;
    	}
     
    	return 1;
    }
     
    void get_hashes(unsigned int hash[], std::string const &in)
    {
    	unsigned char const *str = reinterpret_cast<unsigned char const*>(in.c_str());
    	size_t pos = in.length();
    	hash[0] = RSHash (str, pos);
    	hash[1] = DJBHash (str, pos);
    	hash[2] = FNVHash (str, pos);
    	hash[3] = JSHash (str, pos);
    	hash[4] = PJWHash (str, pos);
    	hash[5] = SDBMHash(str, pos);
    	hash[6] = DEKHash (str, pos);
    }
     
     
     
     
     
     
    /****************\
    | Hash Functions |
    \****************/
     
    unsigned int RSHash(unsigned char const *str, size_t len)
    {
    	unsigned int b = 378551;
    	unsigned int a = 63689;
    	unsigned int hash = 0;
    	size_t i = 0;
     
    	for(i = 0; i < len; str++, i++)
    	{
    		hash = hash * a + (*str);
    		a = a * b;
    	}
     
    	return hash;
    }
     
    unsigned int JSHash(unsigned char const *str, size_t len)
    {
    	unsigned int hash = 1315423911;
    	size_t i = 0;
     
    	for(i = 0; i < len; str++, i++)
    	{
    		hash ^= ((hash << 5) + (*str) + (hash >> 2));
    	}
     
    	return hash;
    }
     
    unsigned int PJWHash(unsigned char const *str, size_t len)
    {
    	const unsigned int BitsInUnsignedInt = static_cast<unsigned int>(sizeof(unsigned int)) * 8;
    	const unsigned int ThreeQuarters = ((BitsInUnsignedInt * 3) / 4);
    	const unsigned int OneEighth = (BitsInUnsignedInt / 8);
    	const unsigned int HighBits = static_cast<unsigned int>(0xFFFFFFFFu) << (BitsInUnsignedInt - OneEighth);
    	unsigned int hash = 0;
    	unsigned int test = 0;
    	size_t i = 0;
     
    	for(i = 0; i < len; str++, i++)
    	{
    		hash = (hash << OneEighth) + (*str);
     
    		if((test = hash & HighBits) != 0)
    		{
    			hash = (( hash ^ (test >> ThreeQuarters)) & (~HighBits));
    		}
    	}
     
    	return hash;
    }
     
    unsigned int SDBMHash(unsigned char const *str, size_t len)
    {
    	unsigned int hash = 0;
    	size_t i = 0;
     
    	for(i = 0; i < len; str++, i++)
    	{
    		hash = (*str) + (hash << 6) + (hash << 16) - hash;
    	}
     
    	return hash;
    }
     
    unsigned int DJBHash(unsigned char const *str, size_t len)
    {
    	unsigned int hash = 5381;
    	size_t i = 0;
     
    	for(i = 0; i < len; str++, i++)
    	{
    		hash = ((hash << 5) + hash) + (*str);
    	}
     
    	return hash;
    }
     
    unsigned int DEKHash(unsigned char const *str, size_t len)
    {
    	unsigned int hash = static_cast<unsigned int>(len);
    	size_t i = 0;
     
    	for(i = 0; i < len; str++, i++)
    	{
    		hash = ((hash << 5) ^ (hash >> 27)) ^ (*str);
    	}
    	return hash;
    }
     
    unsigned int FNVHash(unsigned char const *str, size_t len)
    {
    	const unsigned int fnv_prime = 0x811C9DC5u;
    	unsigned int hash = 0;
    	size_t i = 0;
     
    	for(i = 0; i < len; str++, i++)
    	{
    		hash *= fnv_prime;
    		hash ^= (*str);
    	}
     
    	return hash;
    }

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2009
    Messages
    327
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Janvier 2009
    Messages : 327
    Points : 402
    Points
    402
    Par défaut
    Bonjour,
    Le problème de segmentation fault vient du fait que tu écris avec ton programme dans un endroit de la mémoire que tu ne possède pas.
    Cela arrive le plus souvent lorsque tu sort de l'indice d'un tableau.
    A bientôt

  3. #3
    Rédacteur
    Avatar de 3DArchi
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    7 634
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 7 634
    Points : 13 017
    Points
    13 017
    Par défaut
    Bonsoir,
    Pour continuer dans le sens de wakan, tu devrais mettre des points d'arrêts/ou des dumps pour vérifier tes indices. Tes parcours ne sont pas immédiats, donc tu devrais faire une vérification sur les indices de tableau, ne serait-ce qu'en cas de bug sur une des fonctions de calculs.

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    349
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : Suisse

    Informations forums :
    Inscription : Novembre 2005
    Messages : 349
    Points : 379
    Points
    379
    Par défaut
    Suivant ton IDE + debugger, tu dois pouvoir lancer en mode debug et quand il plante il va te dire à quel endroit.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 2
    Dernier message: 15/01/2008, 12h09
  2. Probleme de segmentation fault avec sprintf
    Par MathG dans le forum C++
    Réponses: 5
    Dernier message: 14/12/2006, 01h12
  3. Aide pour résoudre un Segmentation fault
    Par Premium dans le forum C
    Réponses: 8
    Dernier message: 10/12/2005, 12h26
  4. Segmentation Fault sur un fclose
    Par Beush dans le forum C
    Réponses: 9
    Dernier message: 30/11/2005, 19h30
  5. Segmentation fault sur un gethostbyname ?
    Par Mitox dans le forum Réseau
    Réponses: 9
    Dernier message: 25/11/2005, 16h17

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo