I know the problem has been addressed a million times here, and I know it’s about the typesafety (or rather lack of it) of printf, but I would like some help with the fix since the prof completely refuses C++ solutions.
I have the following structure:
struct node
{
char author[40];
char title[40];
float price;
int stock;
nod *next;
};
I know for a fact that the info is properly stored and I’ve narrowed the problem down to the displaying function:
void display()
{
nod *nod;
nod=p;
while(nod)
{
printf("%s \t %s \t %e \t%d", &node->auhtor, &node->title, &node->price, &node->stock);
node=node->next;}
printf("\n");
}
}
What exactly do I need to change for it to display the same results as
cout<<nod->autor<<'\t'<<nod->titlu<<'\t'<<nod->pret<<'\t'<<nod->stoc<<endl;
Just remove all the ampersands. You want the real deal, so don’t apply the reference operator.