Structures - Reading from file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <fstream>
#include <iostream>
#include <iomanip>
#include <ostream>
using namespace std;


// This program reads records from a file.  The file contains the
// following: student's name, two test grades and final exam grade. 
// It then prints this information to the screen.


const int NAMESIZE = 15;
const int MAXRECORDS = 50;
struct Grades                             // declares a structure
{
	char name[NAMESIZE + 1];
	int test1;
	int test2;
	int final;
	char letter;
};

typedef Grades gradeType[MAXRECORDS];    
 // This makes gradeType a data type
 // that holds MAXRECORDS
 // Grades structures.



// FIll IN THE CODE FOR THE PROTOTYPE OF THE FUNCTION ReadIt
// WHERE THE FIRST ARGUMENT IS AN INPUT FILE, THE SECOND IS THE
// ARRAY OF RECORDS, AND THE THIRD WILL HOLD THE NUMBER OF RECORDS
// CURRENTLY IN THE ARRAY.
void ReadIt(ifstream &, gradeType array, int);

int main()

{    
	 ifstream indata;
	 indata.open("graderoll.txt");
	 int numRecord;                // number of records read in
	 gradeType studentRecord; 
     
	if(!indata)
	{
		cout << "Error opening file. \n";
		cout << "It may not exist where indicated" << endl;
		return 1;
	}

	// FILL IN THE CODE TO CALL THE FUNCTION ReadIt.
	ReadIt(indata,studentRecord,numRecord);
	// output the information 
    for (int count = 0; count < numRecord; count++)
	{
	   cout << studentRecord[count].name << setw(10) 
		    << studentRecord[count].test1
		    << setw(10) << studentRecord[count].test2;
	   cout << setw(10) << studentRecord[count].final << endl;
	}                

	return 0;
}

//**************************************************************
//					readIt
//
//  task:	  This procedure reads records into an array of 
//            records from an input file and keeps track of the 
//		      total number of records
//  data in:  data file containing information to be placed in
//            the array
//  data out: an array of records and the number of records
//
//**************************************************************

void readIt(ifstream &inData, gradeType gradeRec, int &total)

{
   total = 0;
   inData.get(gradeRec[total].name, NAMESIZE);

   while (inData)
   {
     // FILL IN THE CODE TO READ test1
	 inData>>gradeRec[total].test1;
     // FILL IN THE CODE TO READ test2
	 inData>>gradeRec[total].test2;

     // FILL IN THE CODE TO READ final
	 inData>>gradeRec[total].final;
	 	 
	 total++;     // add one to total

     // FILL IN THE CODE TO CONSUME THE END OF LINE
	 
     // FILL IN THE CODE TO READ name
     inData.get(gradeRec[total].name, NAMESIZE);
    
	  
  }

}


I go to compile to see how the program is running and I cant even get that far because of errors I don't even understand.

Error 2 error LNK2019: unresolved external symbol "void __cdecl ReadIt(class std::basic_ifstream<char,struct std::char_traits<char> > &,struct Grades * const,int)" (?ReadIt@@YAXAAV?$basic_ifstream@DU?$char_traits@D@std@@@std@@QAUGrades@@H@Z) referenced in function _main

What is causing this?
Last edited on
C++ is case-sensitive. You declared a function ReadIt but defined a function readIt.
Thank you!
now I am receiving another error.
3 IntelliSense: more than one instance of overloaded function "ReadIt" matches the argument list:

Ill post back with an update.

UPDATE...
Fixed the errors. How do I get it to read multiple lines from the .txt file?
// FILL IN THE CODE TO CONSUME THE END OF LINE
Last edited on
Finished
Topic archived. No new replies allowed.