compiler error

A

Art Cummings

Morning all,

I'm stuck on a compiler error: I've included the entire error and the code
that is causing it is below. The part of the code that is creating the
error is near the top after main, where I try to initial a member of my
structural array. I wanted to be thorough in the information I provided.

Thank you

Art Cummings

"studentInfo[x].attendance=''; this is the offending code,


Compiler: Default compiler
Executing g++.exe...
g++.exe "E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp" -o
"E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.exe" -g3 -I"E:\Boot\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"
-I"E:\Boot\Dev-Cpp\include\c++\3.4.2\backward" -I"E:\Boot\Dev-Cpp\include\c++\3.4.2\mingw32"
-I"E:\Boot\Dev-Cpp\include\c++\3.4.2" -I"E:\Boot\Dev-Cpp\include" -L"E:\Boot\Dev-Cpp\lib"
-g3
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp:50:41: empty
character constant
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp: In function
`int main()':
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp:116: error: a
function-definition is not allowed here before '{' token
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp:116: error:
expected `,' or `;' before '{' token
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp:150: error: a
function-definition is not allowed here before '{' token

E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp:150: error:
expected `,' or `;' before '{' token
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp:185: error: a
function-definition is not allowed here before '{' token
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp:185: error:
expected `,' or `;' before '{' token
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp:192: error:
expected `}' at end of input

Execution terminated


#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <conio.h> //necessary for the _getch function

using namespace std;


const int SIZE = 15; //size for all arrays in student structure
const int ARRAYSIZE = 30; //size of array

struct Student
{
char fName[SIZE]; //array for first name
char lName[SIZE]; //array for last name
char attendance[SIZE]; //array for attendance
int days[SIZE]; //array for days

};

//function prototype for all students
int getInfo(Student[],int, int);

//function prototype for attendance
//void getAttend(Student[],int,fstream &,char *);
void getAttend(Student[],int, int);

//function prototype to display
void displayInfo(Student[],int, int);




int main()
{

Student studentInfo[ARRAYSIZE]; //define an array of 30 students

char status = 'Y';
int type=0,holdret=0;

//initial the structure to all blank strings

for (int x=0; x<ARRAYSIZE; x++)//******************THIS IS THE OFFENDING
CODE*****************************
{

{
for(int i=0;i <= SIZE; i++)
studentInfo[x].attendance='';



}





fstream student;
student.open("c:\\student.dat",ios::eek:ut | ios::in | ios::binary |
ios::app);

cout << "Welcome to Art's attendance program \n";
cout << "To enter data, please select one of the menu numbers \n";
cout << "1. To enter student names \n";
cout << "2. To enter attendance \n";
cout << "3. To view info for students \n";
cout << "-1 to quit \n";

cin >> type;


while(type < 1 || type > 3)
{
cout << "Enter 1,2 or 3 ";
cin >> type;
}
do
{
if (type == 1)
{
holdret = getInfo(studentInfo,ARRAYSIZE,holdret);

cout << "-1 to quit, 1,2 or 3 to continue: ";
cin >> type;
}
else if (type == 2)
{

getAttend(studentInfo,ARRAYSIZE,holdret);
cout << "-1 to quit, 1,2 or 3 to continue: ";
cin >> type;

}

else
{
displayInfo(studentInfo,ARRAYSIZE,holdret);
cout << "-1 to quit, 1,2 or 3 to continue: ";
cin >> type;
}

}while (type !=-1);

student.close();

system("PAUSE");
return 0;

}

/* function header for get info */

int getInfo(Student studnt[], int x,int index)
//int getTest(Student studnt[], int x,int index)
{
//cout << "Index: " << index << endl;
int size=15,i=0,a=0, quit;
if (a != index)
{
for (a=0; a <= index; a++)
cout << a << "." << studnt[a].fName << " " << studnt[a].lName <<
endl;
}
// cout << "A: " << a << endl;
//if (a != 0)

for (i=a;i<x;i++)
{

cout << "Enter first name: " ;
cin.ignore();
cin >> studnt.fName;
cout << "Enter last name: ";

cin >> studnt.lName;
cout << "To quit type -1 type any other letter to continue: ";
cin >> quit;

if (quit == -1)
break;

}
return i;

}


void getAttend(Student studnt[], int size, int index)

{
int stud=0,day=0;
char attend;
int quit=0,a=0;
if (a != index)
{
for (a=0; a <= index; a++)
cout << a << "." << studnt[a].fName << " " << studnt[a].lName <<
endl;
}

do
{
//display the student
cout << "Chose the student you want to enter attendance:
";
cin >> stud;
cout << "Chose the day 0-15: ";
cin.ignore();
cin >> day;
cout << "Enter (P)Present,(A)Absent,(X)Excused: ";
cin >> attend;
studnt[stud].attendance[day]= attend;
cout << "To -1 or any number to continue :";
cin >> quit;
if (quit == -1)
break;
}while(quit != -1);



}

/* function header for display info */

void displayInfo(Student studnt[], int x,int index)

{
int a=0;
for (a=0; a <= index; a++)
cout << a << "." << studnt[a].fName << " " << studnt[a].lName;
for (int i=0;i<16;i++)
cout << "\t" << studnt[a].attendance;
cout << "\n";
}
 
V

Victor Bazarov

Art said:
Morning all,

I'm stuck on a compiler error: I've included the entire error and
the code that is causing it is below. The part of the code that is
creating
the error is near the top after main, where I try to initial a member of
my structural array.

"Try to initial"? No, you are _assigning_ a value to it. At least
that's what you think you're doing. But what value?
I wanted to be thorough in the information I
provided.

You didn't say _what_ you "initial" it with.
Thank you

Art Cummings

"studentInfo[x].attendance=''; this is the offending code,


Compiler: Default compiler
Executing g++.exe...
g++.exe
"E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp" -o
"E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.exe" -g3 -I"E:\Boot\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"
-I"E:\Boot\Dev-Cpp\include\c++\3.4.2\backward" -I"E:\Boot\Dev-Cpp\include\c++\3.4.2\mingw32"
-I"E:\Boot\Dev-Cpp\include\c++\3.4.2" -I"E:\Boot\Dev-Cpp\include" -L"E:\Boot\Dev-Cpp\lib"
-g3
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp:50:41:
empty character constant
[..]


"Empty character constant". What don't you understand? The two
consequent single-quote characters do not represent a valid token in
C++. What do you want to assign to 'studentInfo[x].attendance'?
Nothing? It can't have "nothing" in it. There is no such thing as
"nothing character". If you want to assign something to it, there
has to be something between those apostrophes, or there has to be
no apostrophes at all. You can do

studentInfo[x].attendance = '\0';

or

studentInfo[x].attendance = 0;

(if you want the null character there, for example).

V
 
D

Default User

Art said:
Morning all,

I'm stuck on a compiler error: I've included the entire error and
the code that is causing it is below. The part of the code that is
creating the error is near the top after main, where I try to initial
a member of my structural array. I wanted to be thorough in the
information I provided.
const int SIZE = 15; //size for all arrays in student structure
const int ARRAYSIZE = 30; //size of array

struct Student
{
char fName[SIZE]; //array for first name
char lName[SIZE]; //array for last name
char attendance[SIZE]; //array for attendance
int days[SIZE]; //array for days

};
int main()
{

Student studentInfo[ARRAYSIZE]; //define an array of 30 students

char status = 'Y';
int type=0,holdret=0;

//initial the structure to all blank strings

for (int x=0; x<ARRAYSIZE; x++)//******************THIS IS THE
OFFENDING CODE***************************** {

{
for(int i=0;i <= SIZE; i++)
studentInfo[x].attendance='';



}



The construct '' is meaningless. I think you are confusing it with "",
which is an "empty" string literal consisting of one character, set to
the nul character.

Assuming that you want to set every character to nul, then you could
use:

studentInfo[x].attendance='\0';


However, far easier is to scrap that code altogether and just do it at
initialization time:

Student studentInfo[ARRAYSIZE] = {0};

This will set part of every member of each struct to the equivalent of
0 for that type. But first, ask yourself why you're even doing that.
What do you think this "initialization" (it's really an assignment)
buys you?




Brian
 
D

Default User

Default said:
Art said:
Morning all,

I'm stuck on a compiler error: I've included the entire error and
the code that is causing it is below. The part of the code that is
creating the error is near the top after main, where I try to
initial a member of my structural array. I wanted to be thorough
in the information I provided.
const int SIZE = 15; //size for all arrays in student structure
const int ARRAYSIZE = 30; //size of array

struct Student
{
char fName[SIZE]; //array for first name
char lName[SIZE]; //array for last name
char attendance[SIZE]; //array for attendance
int days[SIZE]; //array for days

};
int main()
{

Student studentInfo[ARRAYSIZE]; //define an array of 30 students

Oh, I should have mentioned that I still think you should stop trying
to write C code in C++. You'd be far better off if you used the
standard containers.

#include <string>
#include <vector>

class Student
{
std::string fname;
std::string lname;
std::string attendance;
std::vector<int> days;
public:
// various operations and constructors
// for dealing with the Student data
};

int main()
{
std::vector<Student> studentInfo(ARRAYSIZE);

etc. etc.




Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top