Emmanuel Delahaye a écrit :
Je conseille ceci :
struct data
{
char *s_nom;
char *s_prenom;
};
|
Pour la création (par exemple) :
struct data record;
char s[64];
fgets(s, sizeof s, stdin);
/* retirer proprement le '\n' */
record.s_nom = strdup(s);
fgets(s, sizeof s, stdin);
/* retirer proprement le '\n' */
record.s_prenom = strdup(s);
|
Nota : strdup() n'est pas standard mais POSIX, donc très portable.
On peut aussi envisager une solution complètement dynamique (constructeur) :
struct data *p_record = data_create (nom, prenom);
|
|