Hi, I'm trying to build a kind of "database" of grocery products.
The idea is have a txt file with the information of the products, name, price, and maybe more stuff. At this point I'm trying to code a function that loads the information from a txt file that I previously write with an only string, I'm trying to check it by executing it in the main fuction and then showing in the console the string character that I previously read, but It doesn't work and I don't know why, so please help.
PS: thanks, and sorry for my grammar mistakes, English is not my first language.
This passes a copy of list to the function. This is called "pass by value". A copy of the variable is sent to the function.
The function then does something with that copy. When the function ends, the copy is thrown away.
This line of code: cout << list.products[0].name;
is working with the original list variable. Your function changed (and then discarded) a copy, the original is unchanged.
As an aside, this:
1 2 3 4
typedefstruct{
tProduct products[MAXprod];
int counter;
}tList;
is C code.
In C++, we do it like this:
1 2 3 4
struct tList{
tProduct products[MAXprod];
int counter;
}