Emmanuel Delahaye C is a sharp tool | 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/
|