Oct 15, 2014 at 11:44pm UTC
I dont think you need to pass your structure to your function, just use the one paramater for the file name then as shadowCODE said do f >> p[i].Name
Oct 16, 2014 at 3:42am UTC
Did you forget to put [i] ?
Oct 16, 2014 at 3:46am UTC
Ah yes! such a simple semantic error, thank you!
I have another problem.
I need to create a Display function which displays the structure array RECORD p
what data type do I pass by? this is incorrect:
Display(p);
void Display()
{
}
Oct 16, 2014 at 3:50am UTC
Since p and N is declared as global variable, I think its fine to have no parameter
Oct 16, 2014 at 4:00am UTC
toupper() doesn't take string as parameter, if you want to make all character uppercase, use loop and process each letter 1 by 1
Last edited on Oct 16, 2014 at 4:01am UTC
Oct 16, 2014 at 4:10am UTC
.Name is a char data type though, and toupper is only used for char data types correct?
What do you mean you have to use a loop to process each letter? if I use a for loop from 0 - 5, doesn't that take;
p[0] of Name = uppercase of p[0] of Name
p[1] of Name = uppercase of p[1] of Name
and so forth
Also, when I try to display each record, it shows the first line of data from the text file correctly, then it just shows a bunch of 0's
Oct 16, 2014 at 4:16am UTC
Yes you are correct but to upper only take a single char, ii always got an error when trying to use uppercase() with array of char
Yes I think
So .Age and .Gpa doesn't show up ?
Oct 16, 2014 at 4:19am UTC
I think there is a problem in how I copied the file to my array.
the data file looks like this:
Martin Smith/ 22 2.2
Austin Clinton/18 3.1
Johnson/ 19 2.9
Maggie Jones/ 23 2.3
Tyler W Brown/ 16 3.4
I get the name, age and gpa of only Martin Smith, but the rest does not show.
and my uppercase function is incorrect, i think the problem stems from my copy function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
void CopyRecords(string Fname)
{
fstream f;
f.open(Fname, ios::in);
for (int i = 0; i < 5; i++)
{
f.getline(p[i].Name, 15, '/' );
f >> p[i].Age;
}
f.close();
}
^ is this correct to retrieve all the information from the text file?
Last edited on Oct 16, 2014 at 4:20am UTC
Oct 16, 2014 at 4:28am UTC
Ooh use cin.ignore(numeric_limits<streamsize>::max(),'\n') after cin>>p[i].Age;
Oct 16, 2014 at 4:30am UTC
Sorry but I cannot use that, as we have not studied numeric_limits, <streamsize> and so forth.
I can use cin.ignore but I need different parameters