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

  FORUM HardWare.fr
  Programmation
  C

  pb de compilation

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

pb de compilation

n°1295921
fce3
Posté le 31-01-2006 à 21:36:56  profilanswer
 

Bonsoir
j essai de realiser un programme en c qui permet de definir les listes chainees et dy effectuer ttes les operation necessaires (ajout, suppression...)
Cependant le compilateur affiche deux erreurs  
1- ' , expected' (1)
2- 'declaration syntax error' (2)
si vs pouvez m aider je vs serai reconnaissante
merci d'avance.
Voici mon programme  
#include<stdio.h>
#include<stddef.h>
#include<stdlib.h>
#define Malloc(t) (t *)malloc(sizeof(t))
enum boolean {true, faulse};
typedef struct_noeud  
  { char nom[15];                    (1)
    struct_noeud *suivant;} adh;      
 
adh *creer(char *nom)           (2)
  {
    adh *tete; tete =NULL;
    adh *p;
    p=NULL;
    p=Malloc(adh);
    p->nom= nom;
    p->suivant=NULL;
    return(p);
  }
void inserer(adh *nom)
  {
  adh *tete;
  adh *p1;
  adh *p2;
  p1=tete; p2=NULL;
  while ((p1!= NULL) && (strcmp (nom, p1->nom) >0))
     {
      p2=p1;
      p1=p1->suivant;
     }
    if (p1==NULL)
 p1=creer(nom);
 else
 {
  p2=creer(nom);
  p2->suivant=p1;
 }
  }
void afficher()
{
  adh *p;
  p=tete;
  while(p) prrintf("%s -> %s", p, p->suivant);
}
boolean chercher(char *nom)
  {
  adh *tete;
  while ((tete-> nom != nom) && (tete -> suivant != NULL))
      tete=tete-> suivant;
   if (tete -> nom == nom)
       return(true);
       else return(faulse);
   }
adh * supprimer(adh *nom)
  {
    adh *pred, *p; boolean found;
    pred=NULL;
    p=NULL;
     if (tete==NULL) perror("liste vide" );
 else
   {
     if (tete-> nom==nom)
        {
   p=tete; tete=tete->suivant;
   free(p);
        }
      else
        {
  found = chercher(nom);
  if (! found) peror("pas dans la liste" );
   else
     {
       pred-> suivant= p-> suivant;
       free(p);
     }
   return(tete);
  }
     }
  }
void main()
{
creer(farid);
ajouter(fatine);
afficher();
getch();
}
 

mood
Publicité
Posté le 31-01-2006 à 21:36:56  profilanswer
 

n°1295923
Joel F
Real men use unique_ptr
Posté le 31-01-2006 à 21:37:35  profilanswer
 

balise cpp :o

n°1296000
Emmanuel D​elahaye
C is a sharp tool
Posté le 31-01-2006 à 22:49:59  profilanswer
 

fce3 a écrit :

j essai de realiser un programme en c qui permet de definir les listes chainees et dy effectuer ttes les operation necessaires (ajout, suppression...)
Cependant le compilateur affiche deux erreurs  
1- ' , expected' (1)
2- 'declaration syntax error' (2)



Compiling: main.c
main.c:7: error: syntax error before '{' token
main.c:8: warning: type defaults to `int' in declaration of `suivant'
main.c:8: warning: data definition has no type or storage class
main.c:8: error: syntax error before '}' token
main.c:8: warning: type defaults to `int' in declaration of `adh'
main.c:8: warning: data definition has no type or storage class
main.c:10: error: syntax error before '*' token
main.c:11: warning: return type defaults to `int'
main.c:11: warning: no previous prototype for 'creer'
main.c: In function `creer':
main.c:12: error: `tete' undeclared (first use in this function)
main.c:12: error: (Each undeclared identifier is reported only once
main.c:12: error: for each function it appears in.)
main.c:13: error: `p' undeclared (first use in this function)
main.c:15: error: syntax error before ')' token
main.c: At top level:
main.c:20: error: syntax error before '*' token
main.c:21: warning: function declaration isn't a prototype
main.c: In function `inserer':
main.c:22: error: `tete' undeclared (first use in this function)
main.c:23: error: `p1' undeclared (first use in this function)
main.c:24: error: `p2' undeclared (first use in this function)
main.c:26: error: implicit declaration of function `strcmp'
main.c:26: warning: nested extern declaration of `strcmp'
<internal>:0: warning: redundant redeclaration of 'strcmp'
main.c:26: error: `nom' undeclared (first use in this function)
main.c: At top level:
main.c:40: warning: function declaration isn't a prototype
main.c: In function `afficher':
main.c:41: error: `p' undeclared (first use in this function)
main.c:42: error: `tete' undeclared (first use in this function)
main.c:43: error: implicit declaration of function `prrintf'
main.c:43: warning: nested extern declaration of `prrintf'
main.c: At top level:
main.c:45: error: syntax error before "chercher"
main.c:46: warning: return type defaults to `int'
main.c:46: warning: no previous prototype for 'chercher'
main.c: In function `chercher':
main.c:47: error: `tete' undeclared (first use in this function)
main.c: At top level:
main.c:54: error: syntax error before '*' token
main.c:54: error: syntax error before '*' token
main.c:55: warning: return type defaults to `int'
main.c:55: warning: function declaration isn't a prototype
main.c: In function `supprimer':
main.c:56: error: `pred' undeclared (first use in this function)
main.c:56: error: `p' undeclared (first use in this function)
main.c:56: warning: left-hand operand of comma expression has no effect
main.c:56: error: `boolean' undeclared (first use in this function)
main.c:56: error: syntax error before "found"
main.c:59: error: `tete' undeclared (first use in this function)
main.c:62: error: `nom' undeclared (first use in this function)
main.c:69: error: `found' undeclared (first use in this function)
main.c:70: error: implicit declaration of function `peror'
main.c:70: warning: nested extern declaration of `peror'
main.c: At top level:
main.c:81: error: conflicting types for 'main_'
C:/clib/frmwrk/inc/main.h:36: error: previous declaration of 'main_' was here
main.c:81: error: conflicting types for 'main_'
C:/clib/frmwrk/inc/main.h:36: error: previous declaration of 'main_' was here
main.c: In function `main_':
main.c:82: error: `farid' undeclared (first use in this function)
main.c:83: error: implicit declaration of function `ajouter'
main.c:83: warning: nested extern declaration of `ajouter'
main.c:83: error: `fatine' undeclared (first use in this function)
main.c:85: error: implicit declaration of function `getch'
main.c:85: warning: nested extern declaration of `getch'
main.c:86:2: warning: no newline at end of file
main.c: In function `supprimer':
main.c:56: warning: statement with no effect
Process terminated with status 1 (0 minutes, 0 seconds)
37 errors, 20 warnings


Joli score pour 90 lignes de code...
 
Début de correction, mais je suis tombé sur un os.


#include<stdio.h>
#include<stddef.h>
#include<stdlib.h>
 
/* -ed- ajoute pour le traitement des chaines... */
#include<string.h>
 
/* -ed-
#define Malloc(t) (t *)malloc(sizeof(t))
 
totalement inutile, voire dangereux...
 
http://mapage.noos.fr/emdel/notes.htm#malloc
 
*/
 
/* -ed-
enum boolean {true, faulse};
en principe, c'est 'false'... */
 
enum boolean
{
   true,
   false
   };
 
/* -ed-
typedef struct_noeud
manque le mot cle 'struct' */
typedef struct noeud
{
   char nom[15];                    /* 1 */
   struct noeud *suivant;
}
adh;
 
adh *creer(char *nom)           /* 2 */
{
   adh *tete;
   tete = NULL;
   /* -ed-
       adh *p;
       p=NULL;
 
       inutile
   */
   adh * p = malloc(sizeof * p);
   /* -ed- malloc() peut echouer */
 
   if (p != NULL)
   {
      /* -ed-
          p->nom= nom;
      Non. Ce n'est pas comme ca qu'on copie les chaines... */
 
      /* -ed- copie securisee. (a n'utiliser que si on a compris comment ca marche...) */
      *p->nom = 0;
      strncat (p->nom, nom, sizeof p->nom - 1);
 
      p->suivant = NULL;
   }
   return (p);
}
 
void inserer(adh *nom)
{
   adh *tete;
   adh *p1;
   adh *p2;
   p1 = tete;
   p2 = NULL;
   while ((p1 != NULL) && (strcmp (nom, p1->nom) > 0))
   {
      p2 = p1;
      p1 = p1->suivant;
   }
   if (p1 == NULL)
      p1 = creer(nom);
   else
   {
      p2 = creer(nom);
      p2->suivant = p1;
   }
}
void afficher()
{
   adh *p;
   
   p = tete;
   /* -ed- tete n'est pas defini. STOP ! */
 


Message édité par Emmanuel Delahaye le 31-01-2006 à 23:00:02

---------------
Des infos sur la programmation et le langage C: http://www.bien-programmer.fr Pas de Wi-Fi à la maison : http://www.cpl-france.org/

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

  pb de compilation

 

Sujets relatifs
erreur de compilation toute bete wxWidgets, visual c++compilation JSP Eclipse
Compilation et deploiement sous MyEclipseLes meilleurs perfs pour Java : compilation code natif, -O, -server ?
petit sondage : options de compilation avec gccErreur de redéfinition à la compilation.
Compilation en ligne de commandeProbleme de Compilation C++
Gcc, La compilation des .o est ok, mais un .o n'est pas reconnuInclude multiples qui font planter la compilation (Gcc Linux)
Plus de sujets relatifs à : pb de compilation


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