Structure Arrays

My assignment is to use structures and arrays to read to a file containing a list of 30 students and storing their information into a structure array. It will then be sent to a function that will see if the students are failing all 3 classes and then send their names to another function that will display their names. Currently I am coming across the issue of a segmentation fault and am not to sure what it causing it.

An example of the file is
Mary Ann 161232 A B F

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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
  

// Description:
// This program will read a text file containing student information and their 
// grade for the current semester and check whether they are failing all 
// courses (3 total).  You are to declare 3 structures called Name, Grades, and 
// StudentInfo respectively.  The structure Name contains two char arrays 
// containing a student’s first and last name.  The structure Grades contains 3 
// chars that hold the grades for three classes the student is taking: math, 
// science, and English.  The last structure StudentInfo contains 3 datatypes: 
// an int for student ID, a Name, and Grades. The structure StudentInfo will 
// hold all the information needed for the student.  In main, you’re to create 
// an array of the structure StudentInfo that can hold as many students as 
// there are in the file StudentInfo.txt.  You’ll open the file in main and 
// call the function ReadFile to read the contents of the file and store them 
// appropriately in the structure array before returning to main.  Once the 
// student info is read and stored, main will call the function IsFailing and 
// check which students are failing all the classes.
//
// ============================================================================

#include <iostream>
#include <fstream>
using namespace std;

// Constant of Number of Students 
const int	numberStudents = 30;

//Structures 
struct    Name
{
	char	firstName[256];
	char	lastName[256];
};

struct    Grades
{
	char    mathGrade;
	char	scienceGrade;
	char	englishGrade;
};

struct    StudentInfo
{
	Name	fullName[512];
	int		studentID;
	Grades	studentGrades;
};

// Function Prototypes
void	ReadFile(ifstream& inFile, StudentInfo	studentData[], int studentAmount);
void	IsFailing(StudentInfo	studentData[], int studentAmount);
void	DispName(StudentInfo	failingStudentData);

// ==== main ==================================================================
//
// ============================================================================

int		main()
{
	// File Variable
	ifstream	inFile;
	// Structure Array of the Student Data
	StudentInfo	studentData[numberStudents];
	// Number of Students in the Class
	int			numStudents = 30;

	// Check to see if file opened
	inFile.open("StudentInfo.txt");
	if (inFile.is_open())
	{
		// Sends inFile, studentData, and numStudents to readFile
		ReadFile	(inFile, studentData, numStudents);
		inFile.close;
	}
	else
	{
		// Error message if file not opened, program terminates after
		cout << "Error opening file. . .";
		exit(EXIT_FAILURE);
	}

	// Sends copied data from inFile to studentData to IsFailing
	IsFailing	(studentData, numStudents);

	return 0;
} // End of main


// ==== ReadFile ==============================================================
//
// This function writes the data from the studentinfo.txt file to the 
// studentInfo array.
//
// Input:
// InFile [IN] -- a text file that will transfer its text to studentInfo array
// studentData[]	[IN] -- an array that will store the text from studentinfo.txt
// studentAmount	[IN] -- an integer value that stores the amount of students 
//
// Output:
// The studentData array is overwritten with the data from studentinfo.txt.
//
// =============================================================================

void	ReadFile(ifstream& inFile, StudentInfo	studentData[], int studentAmount)
{
	// Writes the student's information from the text file to the array
	for (int counter = 0; counter < studentAmount; ++counter)
	{
		inFile >> studentData[counter].fullName->firstName;
		inFile >> studentData[counter].fullName->lastName;
		inFile >> studentData[counter].studentID;
		inFile >> studentData[counter].studentGrades.mathGrade;
		inFile >> studentData[counter].studentGrades.scienceGrade;
		inFile >> studentData[counter].studentGrades.englishGrade;
	}

} // End of ReadFile


// ==== IsFailing =============================================================
//
// This function tests the studentData array for students who have a D or F in 
// all three classes and then sends those students to DispName.
//
// Input:
// studentData[]	[IN] -- a struct array containg the student's information
// studentAmount	[IN] -- an integer value containing the amount of students
//
// Output:
// Student's names who have obatained a failing grade in all three classes are 
// sent to DispName.
//
// =============================================================================

void	IsFailing(StudentInfo	studentData[], int studentAmount)
{
	// Structure for failing students
	StudentInfo		failingStudents;

	// Tests each array to see if any student has failed all three classes
	for (int counter = 0; counter < studentAmount; ++counter)
	{
		if ((studentData[counter].studentGrades.mathGrade == 'D' || 'F') && (studentData[counter].studentGrades.scienceGrade == 'D' || 'F') && (studentData[counter].studentGrades.englishGrade == 'D' || 'F'))
		{
			// Writes data to failingStudents and sends it to DispName
			failingStudents = studentData[counter];
			DispName(failingStudents);
		}
		else
		{
			cout << "The following student(s) are failing: \n" << "No students are failing!";
		}
	}
} // End of IsFailing


// ==== DispName ==============================================================
//
// This function displays the names of the students who are failing all three
// classes.
//
// Input:
// failingStudentData	[IN] -- a structure containing the students information
//
// Output:
// The name of the failing student.
//
// =============================================================================

void	DispName(StudentInfo	failingStudentData)
{
	// Outputs the name of the failing students
	cout << "The following student(s) are failing: \n";
	cout << failingStudentData.fullName->firstName << failingStudentData.fullName->lastName;
} // End of DispName
(1) This program doesn't compile
Line 74:
inFile.close;
should be
inFile.close();


(2) You will probably smash the stack with what happens because of line 45:
Name fullName[512];
It should just be
Name fullName;


(3) Why on earth are you using pointers?
Line 110 and 111
1
2
		inFile >> studentData[counter].fullName->firstName;
		inFile >> studentData[counter].fullName->lastName;

should just be
1
2
		inFile >> studentData[counter].fullName.firstName;
		inFile >> studentData[counter].fullName.lastName;


Line 175 should just be
cout << failingStudentData.fullName.firstName << failingStudentData.fullName.lastName;
Hello,

You look like your on track with learning C++ but why not improve your skills with this course: https://www.udemy.com/learn-cpp-from-scratch/?couponCode=CPPFORUM

This course will help you improve your C++ course and the skills you will learn from it will help you with your future assignments
Topic archived. No new replies allowed.