I dont understand why my program crashs when tryign to fill in some DATA to my struct table declared in main ... I know that a table is itself a pointer right ? So basically i dont realy need to pass the address using &var when using scanf ... but thats when it crashes for me ..
when i tried to pass inputs by scanf("expression",&T[i].var) .. that worked but when showing my content i found out :
As you can see I couldnt event put something for my stat and values totally diffrent from the inputs .. probably cuz taking memory adresses .. but why the Id actually worked and also Lieu is null ? so weird .
struct ChDep
{
int id;
int mins;
char nom[10];
char lieu[10];
double prix;
char stat;
};
//Function Fill some content to my Table
void RemplireHCD(int n, struct ChDep *T)
{
for (int i = 0; i < n; i++)
{
printf("Mission Numero : %d\n", i);
printf("ID = ");
scanf("%d", &T[i].id);
printf("\nDuree = ");
scanf("%d", &T[i].mins);
printf("\nNom = ");
scanf("%s", &T[i].nom);
printf("\nLieu = ");
scanf("%s", &T[i].lieu);
printf("\nPrix = ");
scanf("%lf", &T[i].prix);
printf("\nStatut = ");
scanf("%c", &T[i].stat);
system("cls");
}
}
//Function to show my Struct Table Content
void AfficherHCD(int n, struct ChDep *T)
{
system("cls");
for (int i = 0; i < n; i++)
{
printf("%d > [ ID: %d - Duree : %d - Libelee : %s - Lieu : %s - Prix : %lf - Statut : %c ]\n",
T[i].id, T[i].mins, T[i].nom, T[i].lieu, T[i].prix, T[i].stat);
}
}
int main(int argc, char *argv[])
{
struct ChDep HCD[20];
int n;
printf("SVP donnez Le Nombre de Mission A remplire : \n");
scanf("%d", &n);
system("cls");
RemplireHCD(n, HCD);
AfficherHCD(n, HCD);
getchar();
return 0;
}