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

  FORUM HardWare.fr
  Programmation
  C++

  C : help je ne trouve pas l'erreur (solution trouver merci)

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

C : help je ne trouve pas l'erreur (solution trouver merci)

n°389334
darkthunde​r
Posté le 10-05-2003 à 20:45:05  profilanswer
 

dsl de solliciter votre aide pour cela...  

Code :
  1. #include<stdio.h>
  2. #define NBMAXCOMPOSANT 30
  3. typedef struct{
  4. char NomPort;
  5. int valeur;
  6. }port;
  7. typedef struct{
  8. int NbApparition;
  9. char NomComposant[10];
  10. port entree1;
  11. port entree2;
  12. port sortie;
  13. }composant;
  14. int main(){
  15. composant Matrice[NBMAXCOMPOSANT];
  16. int i=0;
  17. int j=0;
  18. char rep;
  19. while (rep!='0'){
  20. printf("Choisissez le %d composant que vous voulez:\n1.Porte AND\n2.Porte NAND\n3.Porte OR\n4.Porte NOR\n",i+1);
  21. printf("Sinon taper zero pour sortir de la partie saisie\n" );
  22. scanf("%s",&rep);
  23.  switch(rep){
  24.   case'1':Matrice[i].NomComposant[]="AND";
  25.   Matrice[i].NbApparition=i+1;
  26.   i=i+1;system("cls" );
  27.   break;
  28.   case'2':Matrice[i].NomComposant[]="NAND";
  29.   Matrice[i].NbApparition=i+1;
  30.   i=i+1;system("cls" );
  31.   break;
  32.   case'3':Matrice[i].NomComposant[]="OR";
  33.   Matrice[i].NbApparition=i+1;
  34.   i=i+1;system("cls" );
  35.   break;
  36.   case'4':Matrice[i].NomComposant[]="NOR";
  37.   Matrice[i].NbApparition=i+1;
  38.   i=i+1;system("cls" );
  39.   break;
  40.  }
  41. }
  42. printf("Sortie du mode initialisation\n" );
  43. for (j=0;j<=i;j++)
  44. printf("%s %d\n",Matrice[j].NomComposant,Matrice[j].NbApparition);
  45. return 0;
  46. }


 

Code :
  1. --------------------Configuration: version1 - Win32 Debug--------------------
  2. Compiling...
  3. version1.cpp
  4. E:\projet\version1\version1.cpp(48) : error C2059: syntax error : ']'
  5. E:\projet\version1\version1.cpp(53) : error C2059: syntax error : ']'
  6. E:\projet\version1\version1.cpp(58) : error C2059: syntax error : ']'
  7. E:\projet\version1\version1.cpp(63) : error C2059: syntax error : ']'
  8. Error executing cl.exe.
  9. version1.exe - 4 error(s), 0 warning(s)


Message édité par darkthunder le 10-05-2003 à 20:56:44
mood
Publicité
Posté le 10-05-2003 à 20:45:05  profilanswer
 

n°389337
chrisbk
-
Posté le 10-05-2003 à 20:48:26  profilanswer
 

Citation :

Matrice[i].NomComposant[]="AND";


 
illegal. utilise strcpy(Matrice[i].NomComposant,"AND" ) a la place

n°389339
Harkonnen
Modérateur
Un modo pour les bannir tous
Posté le 10-05-2003 à 20:50:22  profilanswer
 

Matrice[i].NomComposant[]
 
Ces crochets n'ont rien à faire la
 
edit: grilled [:grilled]


Message édité par Harkonnen le 10-05-2003 à 20:50:53

---------------
J'ai un string dans l'array (Paris Hilton)
n°389340
Babouchka
You're no fun anymore
Posté le 10-05-2003 à 20:51:17  profilanswer
 

et puis
 
 

Code :
  1. char rep;
  2. scanf("%s",&rep);


 
:pfff:
 
A+

n°389343
Taz
bisounours-codeur
Posté le 10-05-2003 à 20:52:21  profilanswer
 

t'as pas l'imression que tu fais un peu partout la meme chose dans ton switch?
 
autre chose: si tu n'est pas amené à modifé le nom de tes composants
 
tu peux transformer ton champ en  
 
const char * nomcomposant
 
et faire truc.nomcomposant="AND"

n°389344
darkthunde​r
Posté le 10-05-2003 à 20:53:37  profilanswer
 

chrisbk a écrit :

Citation :

Matrice[i].NomComposant[]="AND";


 
illegal. utilise strcpy(Matrice[i].NomComposant,"AND" ) a la place


 
merci ca marche c une bonne astuce d'utiliser string.h
je débute en C j'ai un peu de mal

n°389345
chrisbk
-
Posté le 10-05-2003 à 20:54:46  profilanswer
 

const char *truc[]={"AND","NAND",...};
 
Matrice[i].NomComposant = truc[rep];
Matrice[i].NbApparition=i+1;  
i=i+1;system("cls" );  
 
 
et pof
 
enfin si t'es en C le const risque de coincer....

n°389354
Taz
bisounours-codeur
Posté le 10-05-2003 à 20:57:57  profilanswer
 

non, le const est défini par la norme ANSI


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

  C : help je ne trouve pas l'erreur (solution trouver merci)

 

Sujets relatifs
Trouver toutes les lettres de lecteurs de la machine[opengl]une erreur a la compil, ai-je oublié un fichier d'en-tête ?
VB6: Erreur de compilation incompréhensible....pour moiCalcul TVA avec PHP [NEED HELP]
Commet savoir si le pointeur de fichier se trouve sur une ligne vide ?J'aimerai supprimer une erreur JavaScript
[Delphi/MYSQL] Erreur d'initialisation[ASP] erreur eof
Une erreur tronquée[C]Erreur Winsock 10022(invalid argument)
Plus de sujets relatifs à : C : help je ne trouve pas l'erreur (solution trouver merci)


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