Does printf have side effects?
Posted
by martani_net
on Stack Overflow
See other posts from Stack Overflow
or by martani_net
Published on 2010-04-18T15:09:03Z
Indexed on
2010/04/18
15:13 UTC
Read the original article
Hit count: 337
I have an array of the following strcuture
struct T_info
{
char capitale[255];
char pays[255];
char commentaire[255];
};
struct T_info *tableau;
Then when I populate the array and call printf allone on each element it works fine
strcpy(tab[line].capitale, buffer);
strcpy(tab[line].pays, buffer);
strcpy(tab[line].commentaire, buffer);
printf("%s\n", tab[line].capitale);
printf("%s\n", tab[line].pays);
printf("%s\n", tab[line].commentaire);
but if I call,
printf("%s, %s, %s", tab[line].capitale, tab[line].pays, tab[line].commentaires)
I get wrong resutts, is printf changing its parameters or what is going on?
© Stack Overflow or respective owner