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 :

Probleme pour la réalisation de programme stucturé


Sujet :

C

  1. #1
    Débutant  
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    1 122
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 1 122
    Points : 189
    Points
    189
    Par défaut Probleme pour la réalisation de programme stucturé
    bonjour tout le monde

    J'ai un probleme au niveau niveau du passage d'une fonction à une autre.

    Lors de la compile rien n'est signalé.

    Mai des l'exection, du jeu mode un jour .

    Le programme génere une erreur est se ferme.

    Voici une partie de mon code, j'ai commencé à codé le mode 1 joueur car c'est le plus difficile

    Voici le code, je n'ai pas tout mis car, il y a beaucou de lignes.


    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
     
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
     
    struct element
    {
     
    char pseudo1[20];
    char pseudo2[20];
    int choix;
    char p4[7][7];
    char game;
     
    };
    struct element e;
     
     
    int begingame()
    {
    printf("Bienvenue sur le jeux puissance 4\n");
    printf("\n");
    printf("Developpe par my\n");
    printf("\n");
    printf("Voulez faire une partie à 2 joueur, ou jouer contre l'ordinateur\n");
    printf("Pour une partie à deux, taper 1, contre l'ordinateur taper 2\n");
    scanf("%d",&e.choix);
    if(e.choix==1 ||e.choix==2)
    {
              if(e.choix==1)
    {
        deuxgamer();
    }
        else if(e.choix==2)
             {
             vscomputeur();
             }
    }        
    else
    {
         printf("tempis vous avez fait le mauvais choix\n");
    }
    }
     
    int vscomputeur()
    {
     
    printf("Bonjour je suis l'ia, vous allez m'affronter\n");    
    printf("Cher adverssaire entrer votre nom.\n");    
    scanf("%s",&e.pseudo1);
    printf("\n");
     
     
     
    printf("Vous aurrez les jetons Rouge: R, %s\n " , e.pseudo1);  
    printf("\n");
    printf("Moi, j'aurai les jeton bleu: B\n");
    printf("\n");
    printf("Le jeux debute, Choississe une colonne %s\n " , e.pseudo1);    
    printf("\n");
     
    onegamer();
    gagnantunjoueur();
    }
     
     
    int onegamer()
    {
    e.p4;
    e.game;
    int i,j,k,l;
     
    e.p4[0][1]='A';
    e.p4[0][2]='B';
    e.p4[0][3]='C';
    e.p4[0][4]='D';
    e.p4[0][5]='E';
    e.p4[0][6]='F';
    e.p4[0][7]='G';
     
     
    printf("%c",e.p4[0][1]);
    printf("%c",e.p4[0][2]);
    printf("%c",e.p4[0][3]);
    printf("%c",e.p4[0][4]);
    printf("%c",e.p4[0][5]);
    printf("%c",e.p4[0][6]);
    printf("%c\n\n",e.p4[0][7]);
     
    for(i=1;i<7;i++)
    {
    for(j=0;j<7;j++)
    {
    e.p4[i][j]='*';
    }
    printf("%s",e.p4[i]);
    printf("\n");
    }
    scanf("%c\n",e.game);
    printf("\n\n");
     
    if(e.game=='a')
    {
     e.p4[i][j]='R';
    }  
     
    return (0);
    }
    J'ignore vraiement que est le probleme, mai je pense que c'est la passage de variable entre les fonctions.

    Pouvez vous m'aider svp.

    Merci

    Cordialement

    A bientôt
    je suis un développeur debutant qui cherche à comprendre.

    Certain livre sont pas facile à comprendre.

  2. #2
    Expert éminent sénior
    Avatar de Skyounet
    Homme Profil pro
    Software Engineer
    Inscrit en
    Mars 2005
    Messages
    6 380
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Software Engineer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 6 380
    Points : 13 380
    Points
    13 380
    Par défaut
    Ben met ton programme en fichier joint.

    On a meme pas le main.

    Indentation à revoir, code illisible.

    Parfois dans certaines fonctions tu balances des trucs genre

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    int onegamer()
    {
    e.p4;
    e.game;
    [...]
    }
    Freestyle, tu balances ca comme ca.
    Introduction à Silverlight 4 (new) ; Localisation d'une application Silverlight (new) ;
    Mon espace perso[/B]

    La connaissance s’acquiert par l’expérience, tout le reste n’est que de l’information. Albert Einstein[/SIZE]

  3. #3
    Expert éminent sénior

    Avatar de fearyourself
    Homme Profil pro
    Ingénieur Informaticien Senior
    Inscrit en
    Décembre 2005
    Messages
    5 121
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Ingénieur Informaticien Senior
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2005
    Messages : 5 121
    Points : 11 877
    Points
    11 877
    Par défaut
    Commence par corriger les warnings :

    testit.c: In function 'begingame':
    testit.c:31: warning: implicit declaration of function 'deuxgamer'
    testit.c:35: warning: implicit declaration of function 'vscomputeur'
    testit.c:42: warning: control reaches end of non-void function
    testit.c: In function 'vscomputeur':
    testit.c:49: warning: format '%s' expects type 'char *', but argument 2 has type 'char (*)[19u]'
    testit.c:61: warning: implicit declaration of function 'onegamer'
    testit.c:62: warning: implicit declaration of function 'gagnantunjoueur'
    testit.c:63: warning: control reaches end of non-void function
    testit.c: In function 'onegamer':
    testit.c:68: warning: statement with no effect
    testit.c:69: warning: statement with no effect
    testit.c:98: warning: format '%c' expects type 'char *', but argument 2 has type 'int'
    testit.c:70: warning: unused variable 'l'
    testit.c:70: warning: unused variable 'k'
    Les lignes 48 et 98 sont des erreurs graves.

    Jc

  4. #4
    Débutant  
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    1 122
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 1 122
    Points : 189
    Points
    189
    Par défaut
    Re


    Comme je vous les dis je n'ai pas d'erreur de compilation

    Je vous ai mis mon prog en piece jointe.

    A +
    Fichiers attachés Fichiers attachés
    je suis un développeur debutant qui cherche à comprendre.

    Certain livre sont pas facile à comprendre.

  5. #5
    Expert éminent sénior
    Avatar de Skyounet
    Homme Profil pro
    Software Engineer
    Inscrit en
    Mars 2005
    Messages
    6 380
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Software Engineer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 6 380
    Points : 13 380
    Points
    13 380
    Par défaut
    Pas d'erreurs?

    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
     
    Compiling: main.c
    main.c: In function `begingame':
    main.c:37: warning: implicit declaration of function `deuxgamer'
    main.c:42: warning: implicit declaration of function `vscomputeur'
    main.c: In function `deuxgamer':
    main.c:56: warning: char format, different type arg (arg 2)
    main.c:61: warning: char format, different type arg (arg 2)
    main.c:79: warning: implicit declaration of function `twogamer'
    main.c:83: warning: implicit declaration of function `gagnantunjoueur'
    main.c: In function `vscomputeur':
    main.c:92: warning: char format, different type arg (arg 2)
    main.c:111: warning: implicit declaration of function `onegamer'
    main.c: In function `onegamer':
    main.c:166: warning: format argument is not a pointer (arg 2)
    main.c: In function `twogamer':
    main.c:244: warning: format argument is not a pointer (arg 2)
    main.c: At top level:
    main.c:262: warning: return type defaults to `int'
    main.c:271: warning: return type defaults to `int'
    main.c:282: warning: return type defaults to `int'
    main.c:289: warning: unused parameter 'argc'
    main.c:289: warning: unused parameter 'argv'
    main.c: In function `twogamer':
    main.c:196: warning: statement with no effect
    main.c:258: warning: control reaches end of non-void function
    main.c: In function `gagnantunjoueur':
    main.c:262: warning: control reaches end of non-void function
    main.c: In function `deuxgamer':
    main.c:84: warning: control reaches end of non-void function
    main.c: In function `onegamer':
    main.c:119: warning: statement with no effect
    main.c:120: warning: statement with no effect
    main.c: In function `vscomputeur':
    main.c:115: warning: control reaches end of non-void function
    main.c: In function `begingame':
    main.c:49: warning: control reaches end of non-void function
    main.c: In function `gagnantdeuxjoueurs':
    main.c:271: warning: control reaches end of non-void function
    main.c: In function `end':
    main.c:282: warning: control reaches end of non-void function
    Je rappelle qu'un warning est une erreur.

    Sans compter que ton code est illisible, bourré d'erreur, j'ai trouve ca qui fait plante

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    scanf("%c\n",e.game);
    Remplace par

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    scanf("%c%*c",&e.game);
    Introduction à Silverlight 4 (new) ; Localisation d'une application Silverlight (new) ;
    Mon espace perso[/B]

    La connaissance s’acquiert par l’expérience, tout le reste n’est que de l’information. Albert Einstein[/SIZE]

  6. #6
    Débutant  
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    1 122
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 1 122
    Points : 189
    Points
    189
    Par défaut
    j'utilise dev cpp.

    Comment as tu fais pour trouver ces erreurs Skyrunner.

    A +
    je suis un développeur debutant qui cherche à comprendre.

    Certain livre sont pas facile à comprendre.

  7. #7
    Expert éminent sénior
    Avatar de Skyounet
    Homme Profil pro
    Software Engineer
    Inscrit en
    Mars 2005
    Messages
    6 380
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Software Engineer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 6 380
    Points : 13 380
    Points
    13 380
    Par défaut
    Citation Envoyé par argon
    j'utilise dev cpp.

    Comment as tu fais pour trouver ces erreurs Skyrunner.

    A +
    Outils -> Compilateur
    Coches la case Rajouter ces options lors d'un appel au compilateur.

    Et dans le champs texte au dessous tu rajoutes
    -Wall
    Introduction à Silverlight 4 (new) ; Localisation d'une application Silverlight (new) ;
    Mon espace perso[/B]

    La connaissance s’acquiert par l’expérience, tout le reste n’est que de l’information. Albert Einstein[/SIZE]

  8. #8
    Débutant  
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    1 122
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 1 122
    Points : 189
    Points
    189
    Par défaut
    Re

    Je les fais.

    Par momment j'ai cette erreur qui s'affiche.

    [Build Error] [main.o] Error 1
    Est ce que mes appelles de fonction sont corrects svp.

    A+
    je suis un développeur debutant qui cherche à comprendre.

    Certain livre sont pas facile à comprendre.

  9. #9
    Expert éminent sénior
    Avatar de Emmanuel Delahaye
    Profil pro
    Retraité
    Inscrit en
    Décembre 2003
    Messages
    14 512
    Détails du profil
    Informations personnelles :
    Âge : 67
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2003
    Messages : 14 512
    Points : 20 985
    Points
    20 985
    Par défaut
    Citation Envoyé par argon
    Lors de la compile rien n'est signalé.
    Tu devrais apprendre à mieux regler ton compilateur...
    Au minimum : -Wall -Wextra -O2
    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
     
    Compiling: main.c
    main.c:19: warning: function declaration isn't a prototype
    main.c: In function `begingame':
    main.c:31: error: implicit declaration of function `deuxgamer'
    main.c:31: warning: nested extern declaration of `deuxgamer'
    main.c:35: error: implicit declaration of function `vscomputeur'
    main.c:35: warning: nested extern declaration of `vscomputeur'
    main.c: At top level:
    main.c:45: warning: function declaration isn't a prototype
    main.c: In function `vscomputeur':
    main.c:49: warning: char format, different type arg (arg 2)
    main.c:61: error: implicit declaration of function `onegamer'
    main.c:61: warning: nested extern declaration of `onegamer'
    main.c:62: error: implicit declaration of function `gagnantunjoueur'
    main.c:62: warning: nested extern declaration of `gagnantunjoueur'
    main.c: At top level:
    main.c:67: warning: function declaration isn't a prototype
    main.c: In function `onegamer':
    main.c:98: warning: format argument is not a pointer (arg 2)
    main.c:70: warning: unused variable `k'
    main.c:70: warning: unused variable `l'
    main.c:68: warning: statement with no effect
    main.c:69: warning: statement with no effect
    Process terminated with status 1 (0 minutes, 0 seconds)
    4 errors, 13 warnings
    J'ai réorganisé le code. Pour le moment, je ne vois pas d'utilité à avoir des données persistantes. D'autre part, pour le moment, la portée des données semble être limitée aux fonctions.

    Bien sûr, tout celà peut changer si le code évolue.
    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
     
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
     
    static int onegamer(void)
    {
       int i, j;
       char p4[7][7];
     
       p4[0][1] = 'A';
       p4[0][2] = 'B';
       p4[0][3] = 'C';
       p4[0][4] = 'D';
       p4[0][5] = 'E';
       p4[0][6] = 'F';
       p4[0][7] = 'G';
     
     
       printf("%c", p4[0][1]);
       printf("%c", p4[0][2]);
       printf("%c", p4[0][3]);
       printf("%c", p4[0][4]);
       printf("%c", p4[0][5]);
       printf("%c", p4[0][6]);
       printf("%c\n\n", p4[0][7]);
     
       for (i = 1;i < 7;i++)
       {
          for (j = 0;j < 7;j++)
          {
             p4[i][j] = '*';
          }
          printf("%s", p4[i]);
          printf("\n");
       }
       {
          char game;
          scanf("%c\n", &game);
          printf("\n\n");
     
          if (game == 'a')
          {
             p4[i][j] = 'R';
          }
       }
       return 0;
    }
     
     
    static void gagnantunjoueur(void)
    {
       /* to-do */
    }
     
    static void deuxgamer(void)
    {
       /* to-do */
    }
     
    static int vscomputeur(void)
    {
       char pseudo1[20];
     
       printf("Bonjour je suis l'ia, vous allez m'affronter\n");
       printf("Cher adverssaire entrer votre nom.\n");
       scanf("%s", pseudo1);
       printf("\n");
     
     
     
       printf("Vous aurrez les jetons Rouge: R, %s\n " , pseudo1);
       printf("\n");
       printf("Moi, j'aurai les jeton bleu: B\n");
       printf("\n");
       printf("Le jeux debute, Choississe une colonne %s\n " , pseudo1);
       printf("\n");
     
       onegamer();
       gagnantunjoueur();
    }
     
    static void begingame(void)
    {
       int choix;
     
       printf("Bienvenue sur le jeux puissance 4\n");
       printf("\n");
       printf("Developpe par my\n");
       printf("\n");
       printf("Voulez faire une partie à 2 joueur, ou jouer contre l'ordinateur\n");
       printf("Pour une partie à deux, taper 1, contre l'ordinateur taper 2\n");
       scanf("%d", &choix);
       if (choix == 1 || choix == 2)
       {
          if (choix == 1)
          {
             deuxgamer();
          }
          else if (choix == 2)
          {
             vscomputeur();
          }
       }
       else
       {
          printf("tempis vous avez fait le mauvais choix\n");
       }
    }
     
    int main (void)
    {
       begingame();
       return 0;
    }
    Pas de Wi-Fi à la maison : CPL

  10. #10
    Débutant  
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    1 122
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 1 122
    Points : 189
    Points
    189
    Par défaut
    Bonjour tout le monde

    Que veut dire cette erreur?

    [Build Error] [main.o] Error 1
    Merci

    Cordialement

    A bientôt
    je suis un développeur debutant qui cherche à comprendre.

    Certain livre sont pas facile à comprendre.

  11. #11
    Expert éminent sénior
    Avatar de Emmanuel Delahaye
    Profil pro
    Retraité
    Inscrit en
    Décembre 2003
    Messages
    14 512
    Détails du profil
    Informations personnelles :
    Âge : 67
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2003
    Messages : 14 512
    Points : 20 985
    Points
    20 985
    Par défaut
    Citation Envoyé par argon
    Que veut dire cette erreur?
    Rien de précis. Si tu as Code::Blocks, fait un rebuild et montre le contenu de l'onglet 'Build log'.
    Pas de Wi-Fi à la maison : CPL

  12. #12
    Débutant  
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    1 122
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 1 122
    Points : 189
    Points
    189
    Par défaut
    Re

    j'utilise dev cpp

    A+
    je suis un développeur debutant qui cherche à comprendre.

    Certain livre sont pas facile à comprendre.

  13. #13
    Expert éminent sénior
    Avatar de Emmanuel Delahaye
    Profil pro
    Retraité
    Inscrit en
    Décembre 2003
    Messages
    14 512
    Détails du profil
    Informations personnelles :
    Âge : 67
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2003
    Messages : 14 512
    Points : 20 985
    Points
    20 985
    Par défaut
    Citation Envoyé par argon
    j'utilise dev cpp
    Fait un rebuild all...
    Pas de Wi-Fi à la maison : CPL

  14. #14
    Débutant  
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    1 122
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 1 122
    Points : 189
    Points
    189
    Par défaut
    Re

    que voulez vous dire par


    Fait un rebuild all...
    a+
    je suis un développeur debutant qui cherche à comprendre.

    Certain livre sont pas facile à comprendre.

  15. #15
    Expert éminent sénior

    Avatar de fearyourself
    Homme Profil pro
    Ingénieur Informaticien Senior
    Inscrit en
    Décembre 2005
    Messages
    5 121
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Ingénieur Informaticien Senior
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2005
    Messages : 5 121
    Points : 11 877
    Points
    11 877
    Par défaut
    Citation Envoyé par argon
    Re

    que voulez vous dire par


    Rebuild all
    a+
    Recompile tous les fichiers

    Jc

  16. #16
    Expert éminent sénior
    Avatar de Emmanuel Delahaye
    Profil pro
    Retraité
    Inscrit en
    Décembre 2003
    Messages
    14 512
    Détails du profil
    Informations personnelles :
    Âge : 67
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2003
    Messages : 14 512
    Points : 20 985
    Points
    20 985
    Par défaut
    Citation Envoyé par argon
    que voulez vous dire par<...>
    Exécuter
    Tout reconstruire
    Pas de Wi-Fi à la maison : CPL

Discussions similaires

  1. Réponses: 6
    Dernier message: 02/08/2006, 17h24
  2. Probleme pour la réalisation d'applet
    Par argon dans le forum Applets
    Réponses: 2
    Dernier message: 15/02/2006, 07h55
  3. Réponses: 7
    Dernier message: 16/04/2005, 08h55
  4. [LG]Divers problémes pour un programme.
    Par Horus TCT dans le forum Langage
    Réponses: 14
    Dernier message: 24/05/2003, 23h04

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