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 :

Erreur de segmentation en c


Sujet :

C#

  1. #1
    Membre à l'essai
    Inscrit en
    Décembre 2012
    Messages
    5
    Détails du profil
    Informations forums :
    Inscription : Décembre 2012
    Messages : 5
    Par défaut Erreur de segmentation en c
    bonsoir, j'ai un problème avec mon code c, j'ai une erreur de segmentation SVP quelqu'un peut m'aider
    Merci portion du code ci-dessous
    Code : 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
     for (i=0;i<=taille;i++)
         {	 
    	if (tab1[i]!=100)
    	   {
    	    if (i<t)
    		{
    		 if ((tab1[i]+tab2[i])<26)
    		   {
     
    		    strcpy(s,mot);
           		    car[0]=table[tab1[i]+tab2[i]];
    		    printf("%c\n",car[0]);
    		    strcat(s,car);
     		    printf("%s\n",s);
     
    		   }
    		 else
    		   {
    		    strcpy(s,mot);
                        car[0]=table[tab1[i]+tab2[i]-26];
     
    		    strcat(s,car);
     		    printf("%s\n",s);		    
     
    		   }
    		}
    	     else
    		{
    		  if ((tab1[i]+tab2[i-t])<26)
    		   {
    		    strcpy(s,mot);
    		    car[0]=table[tab1[i]+tab2[i]];
     
    		    strcat(s,car);
     		    printf("%s\n",s);
     
    		   }
    		  else
    		   {
                        strcpy(s,mot);
    		    car[0]=table[tab1[i]+tab2[i-t]-26];
     
    		    strcat(s,car);
     		    printf("%s\n",s);
     
    		   }
    		}
    	   }
    	else
    	  {
    	   strcpy(s,mot);
    	   car[0]=text[i];
     
    	   strcat(s,car);
     
    	  }
     
         }
    printf("ciphertext\n");
    printf("%s\n",s);		 
    return 0;

  2. #2
    Membre expérimenté
    Homme Profil pro
    Chef de Projet
    Inscrit en
    Décembre 2012
    Messages
    113
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Chef de Projet
    Secteur : Associations - ONG

    Informations forums :
    Inscription : Décembre 2012
    Messages : 113
    Par défaut
    Bonsoir,

    Je pense que tu aurais plus de chance en postant ta requête sur le forum dédié au C et non sur le forum dédié au C#.

    Ensuite, et pour t'aider à obtenir des réponses, je t'invite d'une part à compléter ton code (il y a tellement de variables dont on ne sait pas comment elles sont initialisées qu'il est impossible de dire d'où vient ton erreur à la simple lecture du code. Au hasard tab ? car ? table ? taille et j'en passe).

    D'autre part, il existe une balise pour insérer du code et qui en améliore grandement la lisibilité via la coloration syntaxique et les références en numérotant les lignes.

    Voici un exemple de ce que cela peut donner :
    Code : 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
    for (i=0;i<=taille;i++)
    {
    if (tab1[i]!=100)
    {
    if (i<t)
    {
    if ((tab1[i]+tab2[i])<26)
    {
     
    strcpy(s,mot);
    car[0]=table[tab1[i]+tab2[i]];
    printf("%c\n",car[0]);
    strcat(s,car);
    printf("%s\n",s);
     
    }
    else
    {
    strcpy(s,mot);
    car[0]=table[tab1[i]+tab2[i]-26];
     
    strcat(s,car);
    printf("%s\n",s);
     
    }
    }
    else
    {
    if ((tab1[i]+tab2[i-t])<26)
    {
    strcpy(s,mot);
    car[0]=table[tab1[i]+tab2[i]];
     
    strcat(s,car);
    printf("%s\n",s);
     
    }
    else
    {
    strcpy(s,mot);
    car[0]=table[tab1[i]+tab2[i-t]-26];
     
    strcat(s,car);
    printf("%s\n",s);
     
    }
    }
    }
    else
    {
    strcpy(s,mot);
    car[0]=text[i];
     
    strcat(s,car);
     
    }
     
    }
    printf("ciphertext\n");
    printf("%s\n",s);
    return 0;
    Il ne manque alors plus que de l'indentation

  3. #3
    Membre à l'essai
    Inscrit en
    Décembre 2012
    Messages
    5
    Détails du profil
    Informations forums :
    Inscription : Décembre 2012
    Messages : 5
    Par défaut
    Merci pour toutes ces remarques
    Code : 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
     
     
    # include <stdio.h>
    # include <math.h>
    #include <stdlib.h>
    #include <unistd.h>
    # include <string.h>
    int main(int argc,char *argv[])
      {
        int i=0;
        char *text;
        int taille,t ;
        int j=0;
        int tab1[strlen(text)];
        int tab2[strlen(argv[1])];
        char s[7];
        int taille_m;
        char car[2]={' ',' '};
        char mot[2];
        char table[26];
        table[0]='A' ;
        table[1]='B' ;
        table[2]='C' ;
        table[3]='D' ;
        table[4]='E' ;
        table[5]='F' ;
        table[6]='G' ;
        table[7]='H' ;
        table[8]='I' ;
        table[9]='J' ;
        table[10]='K' ;
        table[11]='L' ;
        table[12]='M' ;
        table[13]='N' ;
        table[14]='O' ;
        table[15]='P' ;
        table[16]='Q' ;
        table[17]='R' ;
        table[18]='S' ;
        table[19]='T' ;
        table[20]='U' ;
        table[21]='V' ;
        table[22]='W' ;
        table[23]='X' ;
        table[24]='Y' ;
        table[25]='Z' ;
        printf("entrez le texte\n");
        scanf("%s",text);
        printf("%s",text);
        //s="bnsp";
        taille=strlen(text);
        printf("%d\n",taille);
        // strcpy(car," \0");
        //car[0]=" ";
        car[1]='\0';
        strcpy(mot,"aa");
        strcpy(s," ");
    	printf( "bonjour");
    // I retrieves the index of each character in the text that corresponds to the letter of the table
        for (i=0;i<=taille;i++)
         {
          while ((j<taille)&&(text[i]!=table[j]))
           {
    	j++;
           }
    	if (text[i]==table[j]) 
             {
    	   tab1[i]=j;
    	 }
    	else
    	 if (j>taille)
    	 {
    	   tab1[i]=100;
    	 }
         }
    // I retrieves the index of each character of the key that corresponds to the letter of the table
          t=strlen(argv[1]);
          printf("%d\n",t);
          j=0;
          for (i=0;i<=t;i++)
    	{
          while ((j<t)&&(text[i]!=argv[1][i]))
           {
    	j++;
           }
    	if (argv[1][i]!=table[j]) 
             {
    	   tab2[i]=j;
    	 }
     
    	}
    //
     
     for (i=0;i<=taille;i++)
         {	 
    	if (tab1[i]!=100)
    	   {
    	    if (i<t)
    		{
    		 if ((tab1[i]+tab2[i])<26)
    		   {
     
    		    strcpy(s,mot);
           		    car[0]=table[tab1[i]+tab2[i]];
    		    printf("%c\n",car[0]);
    		    strcat(s,s);
     		    printf("%s\n",s);
     
    		   }
    		 else
    		   {
    		    strcpy(s,mot);
                        car[0]=table[tab1[i]+tab2[i]-26];
     
    		    strcat(s,s);
     		    printf("%s\n",s);		    
     
    		   }
    		}
    	     else
    		{
    		  if ((tab1[i]+tab2[i-t])<26)
    		   {
    		    strcpy(s,mot);
    		    car[0]=table[tab1[i]+tab2[i]];
     
    		    strcat(s,s);
     		    printf("%s\n",s);
     
    		   }
    		  else
    		   {
                        strcpy(s,mot);
    		    car[0]=table[tab1[i]+tab2[i-t]-26];
     
    		    strcat(s,s);
     		    printf("%s\n",s);
     
    		   }
    		}
    	   }
    	else
    	  {
    	   strcpy(s,mot);
    	   car[0]=text[i];
     
    	   strcat(s,s);
     
    	  }
     
         }
    printf("ciphertext\n");
    printf("%s\n",s);		 
    return 0;
    }

  4. #4
    Membre à l'essai
    Inscrit en
    Décembre 2012
    Messages
    5
    Détails du profil
    Informations forums :
    Inscription : Décembre 2012
    Messages : 5
    Par défaut Erreur de segmentation
    bonsoir, j'ai l'impression que mon érreur vient de la fonction strcat, quelqu'un peut m'aider là dessus
    Merci

  5. #5
    Membre à l'essai
    Inscrit en
    Décembre 2012
    Messages
    5
    Détails du profil
    Informations forums :
    Inscription : Décembre 2012
    Messages : 5
    Par défaut
    Code : 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
     
     
    # include <stdio.h>
    # include <math.h>
    #include <stdlib.h>
    #include <unistd.h>
    # include <string.h>
    int main(int argc,char *argv[])
      {
        int i=0;
        char *text;
        int taille,t ;
        int j=0;
        int tab1[strlen(text)];
        int tab2[strlen(argv[1])];
        char s[7];
        int taille_m;
        char car[2]={' ',' '};
        char mot[2];
        char table[26];
        table[0]='A' ;
        table[1]='B' ;
        table[2]='C' ;
        table[3]='D' ;
        table[4]='E' ;
        table[5]='F' ;
        table[6]='G' ;
        table[7]='H' ;
        table[8]='I' ;
        table[9]='J' ;
        table[10]='K' ;
        table[11]='L' ;
        table[12]='M' ;
        table[13]='N' ;
        table[14]='O' ;
        table[15]='P' ;
        table[16]='Q' ;
        table[17]='R' ;
        table[18]='S' ;
        table[19]='T' ;
        table[20]='U' ;
        table[21]='V' ;
        table[22]='W' ;
        table[23]='X' ;
        table[24]='Y' ;
        table[25]='Z' ;
        printf("entrez le texte\n");
        scanf("%s",text);
        printf("%s",text);
        //s="bnsp";
        taille=strlen(text);
        printf("%d\n",taille);
        // strcpy(car," \0");
        //car[0]=" ";
        car[1]='\0';
        strcpy(mot,"aa");
        strcpy(s," ");
    	printf( "bonjour");
    // I retrieves the index of each character in the text that corresponds to the letter of the table
        for (i=0;i<=taille;i++)
         {
          while ((j<taille)&&(text[i]!=table[j]))
           {
    	j++;
           }
    	if (text[i]==table[j]) 
             {
    	   tab1[i]=j;
    	 }
    	else
    	 if (j>taille)
    	 {
    	   tab1[i]=100;
    	 }
         }
    // I retrieves the index of each character of the key that corresponds to the letter of the table
          t=strlen(argv[1]);
          printf("%d\n",t);
          j=0;
          for (i=0;i<=t;i++)
    	{
          while ((j<t)&&(text[i]!=argv[1][i]))
           {
    	j++;
           }
    	if (argv[1][i]!=table[j]) 
             {
    	   tab2[i]=j;
    	 }
     
    	}
    //
     
     for (i=0;i<=taille;i++)
         {	 
    	if (tab1[i]!=100)
    	   {
    	    if (i<t)
    		{
    		 if ((tab1[i]+tab2[i])<26)
    		   {
     
    		    strcpy(s,mot);
           		    car[0]=table[tab1[i]+tab2[i]];
    		    printf("%c\n",car[0]);
    		    strcat(s,car);
     		    printf("%s\n",s);
     
    		   }
    		 else
    		   {
    		    strcpy(s,mot);
                        car[0]=table[tab1[i]+tab2[i]-26];
     
    		    strcat(s,car);
     		    printf("%s\n",s);		    
     
    		   }
    		}
    	     else
    		{
    		  if ((tab1[i]+tab2[i-t])<26)
    		   {
    		    strcpy(s,mot);
    		    car[0]=table[tab1[i]+tab2[i]];
     
    		    strcat(s,s);
     		    printf("%s\n",car);
     
    		   }
    		  else
    		   {
                        strcpy(s,mot);
    		    car[0]=table[tab1[i]+tab2[i-t]-26];
     
    		    strcat(s,car);
     		    printf("%s\n",s);
     
    		   }
    		}
    	   }
    	else
    	  {
    	   strcpy(s,mot);
    	   car[0]=text[i];
     
    	   strcat(s,car);
     
    	  }
     
         }
    printf("ciphertext\n");
    printf("%s\n",s);		 
    return 0;
    }

  6. #6
    Inactif  
    Homme Profil pro
    Chef de projet NTIC
    Inscrit en
    Janvier 2007
    Messages
    6 604
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 64
    Localisation : France

    Informations professionnelles :
    Activité : Chef de projet NTIC

    Informations forums :
    Inscription : Janvier 2007
    Messages : 6 604
    Par défaut
    Comme déjà dit, sur le forum C quelqu'un pourra surement t'aider, mais ici tu es sur le forum c# (C-SHARP) .

    Accessoirement strlen(text) ici est appelé alors que text n'est pas initialisé.

Discussions similaires

  1. Erreurs de segmentation !
    Par anti-conformiste dans le forum Applications et environnements graphiques
    Réponses: 16
    Dernier message: 18/10/2005, 11h11
  2. Erreur de segmentation
    Par Trunks dans le forum C
    Réponses: 3
    Dernier message: 06/10/2005, 18h28
  3. Erreur de segmentation (Inconnue)
    Par Dark-Meteor dans le forum C
    Réponses: 5
    Dernier message: 08/09/2005, 13h42
  4. [Dev-C++] Erreur de segmentation...
    Par sas dans le forum Dev-C++
    Réponses: 11
    Dernier message: 26/03/2005, 14h25
  5. erreur de segmentation
    Par transistor49 dans le forum C++
    Réponses: 10
    Dernier message: 15/03/2005, 11h18

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