| | |
Question about putting structs into arrays
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2004
Posts: 2
Reputation:
Solved Threads: 0
Hello,
First off, a couple of things have to be known.
1) Do you know how to read in the data and sperate it into just regualar variables?
2) Do you know how to construct a strut variable type?
2) Do you know how to make an array of structs?
What you are asking for is pretty broad, and without out right writing the program for you , you need to say what exactly you are having a problem with.
DKnight764
First off, a couple of things have to be known.
1) Do you know how to read in the data and sperate it into just regualar variables?
2) Do you know how to construct a strut variable type?
2) Do you know how to make an array of structs?
What you are asking for is pretty broad, and without out right writing the program for you , you need to say what exactly you are having a problem with.
DKnight764
•
•
Join Date: Nov 2004
Posts: 2
Reputation:
Solved Threads: 0
Ok first...no i'm not sure how to read in the data and separate it and the only thing i know about structs is what i read in the book...
But this is what i have so far:
I know this isnt right because when i run it nothing happens. It compiles but that's about it. That's how they put the struct into an array in my C++ book and that's the way the got it to print out too.
I have to read in the data from a text file and properly put them in the array. 100 customers is the allowed limit. I figure if i cant get the data into the array then I can finish the rest of the program myself.
But this is what i have so far:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> using namespace std; struct custInfo{ int custNumber, numItems; string firstName, lastName; float amtSpent; }; void getData(ifstream &infile, custInfo list[], int listSize); int main(){ ifstream infile; custInfo custList[100]; int size, input; infile.open("E:sales.txt"); if(!infile){ cout<<"Cannot open input file."<<endl; return 1; } getData(input, custList[], size); return 0; } void getData(ifstream &infile, custInfo list[], int listSize){ for (int i=0; i<100; i++){ infile>>list[i].custNumber>>list[i].firstName >>list[i].lastName>>list[i].numItems >>list[i].amtSpent; } for (int count=0; count<100; count++){ cout<<list[count].custNumber<<" " <<list[count].firstName<<" " <<list[count].lastName<<" " <<list[count].numItems<<" " <<list[count].amtSpent; } }
I know this isnt right because when i run it nothing happens. It compiles but that's about it. That's how they put the struct into an array in my C++ book and that's the way the got it to print out too.
I have to read in the data from a text file and properly put them in the array. 100 customers is the allowed limit. I figure if i cant get the data into the array then I can finish the rest of the program myself.
Last edited by alc6379; Nov 3rd, 2004 at 10:19 pm. Reason: added [code] tags
![]() |
Similar Threads
- Quick Question (C++)
- contact info in array of structs (C++)
- c++ struct (C++)
- Please help with assignment (C++)
- Little Simple array question :) (C)
- emu8086 and arrays (Assembly)
- Multidimesional Arrays in C (C++)
Other Threads in the C++ Forum
- Previous Thread: **help me out***
- Next Thread: pythagorean triple
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph homeworkhelp iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





