Probleme en C
hue_canabis
Messages postés
36
Date d'inscription
Statut
Membre
Dernière intervention
-
hue_canabis Messages postés 36 Date d'inscription Statut Membre Dernière intervention -
hue_canabis Messages postés 36 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
que veut dire ces 2 lignes:
p1=(canton*)malloc(1*sizeof(canton));
(canton) *p1;
sachant que canton est une struct.
merci
que veut dire ces 2 lignes:
p1=(canton*)malloc(1*sizeof(canton));
(canton) *p1;
sachant que canton est une struct.
merci
3 réponses
En fait la,je pense que tu demandes la taille (en octet) de ta srtucture. mais c'est pas très clair, si tu pouvais donner une plus grande partie de ton code, je verrais mieux ce que ca fait.
HEADER:
typedef struct station station;
struct station
{
char nom[30];
char cote[7];
int temp_arret;
int kilometre;
};
typedef struct canton canton;
struct canton
{
char nomducanton[30];
int vitessemax;
int longueur;
station station;
canton *canton_suiv;
};
canton *p1;
canton *pcourant;
canton *TL;
SOURCE:
p1=(canton*)malloc(1*sizeof(canton));
(canton) *p1;
TL=p1;
pcourant=p1;
printf ("\n\tEntrez le nom du 1er canton:");
fflush(stdin);
fgets(pcourant->nomducanton,sizeof(pcourant->nomducanton),stdin);
Chaine = strlen(pcourant->nomducanton);
pcourant->nomducanton[Chaine-1]=pcourant->nomducanton[Chaine];
pcourant->nomducanton[Chaine]='*';
printf ("\tEntrez la longueur du canton en m:");
fflush(stdin);
scanf("%i",&pcourant->longueur);
longueur_ligne=longueur_ligne+pcourant->longueur;
voila lol, c la partie que je n'ai pas compris hahaha
typedef struct station station;
struct station
{
char nom[30];
char cote[7];
int temp_arret;
int kilometre;
};
typedef struct canton canton;
struct canton
{
char nomducanton[30];
int vitessemax;
int longueur;
station station;
canton *canton_suiv;
};
canton *p1;
canton *pcourant;
canton *TL;
SOURCE:
p1=(canton*)malloc(1*sizeof(canton));
(canton) *p1;
TL=p1;
pcourant=p1;
printf ("\n\tEntrez le nom du 1er canton:");
fflush(stdin);
fgets(pcourant->nomducanton,sizeof(pcourant->nomducanton),stdin);
Chaine = strlen(pcourant->nomducanton);
pcourant->nomducanton[Chaine-1]=pcourant->nomducanton[Chaine];
pcourant->nomducanton[Chaine]='*';
printf ("\tEntrez la longueur du canton en m:");
fflush(stdin);
scanf("%i",&pcourant->longueur);
longueur_ligne=longueur_ligne+pcourant->longueur;
voila lol, c la partie que je n'ai pas compris hahaha