Hi,
I'm trying to use pointers as the parameters of a function. The pointers are supposed to point to the items held within a text file which was previously created by the use of an array of structs.
This is what I've done so far:-
My question is just in regards to the bold text errors. I'm unsure on how to combine having the pointers point to the struct's items, while still having them accessible by a function call (which I haven't yet placed into main).Code:#include <iostream> #include <fstream> using namespace std; struct items { double price; bool luxury; }; void FunctionsName(double *pointer2price, bool *pointer2luxury); int main() { items StructArrayName[10]; ifstream StreamName; StreamName.open("myfile2.txt"); if(!StreamName) { cout << "phail " << endl; } for(int i = 0;i < 10; i++) { StreamName >> StructArrayName[i].price >> StructArrayName[i].luxury; } double *pointer2price; StructArrayName->price = *pointer2price;//uninitialized local variable 'pointer2price' used bool *pointer2luxury; StructArrayName->luxury = *pointer2luxury;//uninitialized local variable 'pointer2luxury' used StreamName.close(); system ("pause"); return 0; } void FunctionsName(double *pointer2price, bool *pointer2luxury) { for(int a = 0;a<10;a++) { if(*pointer2price>9.99) { *pointer2price = 9.95; } if(*pointer2luxury = 1) { *pointer2luxury = 0; } } }
.....I'm hoping that makes sense. Many thanks.