Sep 1, 2011 at 7:41am UTC
where is the error for the mark8[]?
any expert can help me detect and tell me how to solve?
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
/*
string mystring;
char myntcs[]="some text";
mystring = myntcs;
*/
int main()
{
ifstream indata;
string n;
char tmp[100];
int m1, m2, m3, m4;
int m5, m6,m7;
int m8;
string name[100];
int mark1[100]={0},mark2[100]={0},mark3[100]={0},mark4[100]={0},mark5[100]={0},mark6[100]={0},mark7[100]={0};
// int mark8[100]={0};
indata.open("StudentList.dat");
int size=0;
if(indata.fail())
{
cout<<"error"<<endl;
}
else
{
while ((!indata.eof()))
{
getline(indata,n);
indata>>m1;
indata>>m2;
indata>>m3;
indata>>m4;
indata>>m5;
indata>>m6;
indata>>m7;
//indata>>m8;
indata.getline (tmp,100);
if(!indata.eof())
{
name[size]=n;
mark1[size]=m1;
mark2[size]=m2;
mark3[size]=m3;
mark4[size]=m4;
mark5[size]=m5;
mark6[size]=m6;
mark7[size]=m7;
//mark8[size]=m8;
size++;
}
}
}
for(int x=0;x<100;x++)
{if(mark1[x]!=0&&mark2[x]!=0&&mark3[x]!=0&&mark4[x]!=0)
{ cout<<name[x]<<"\t"<<mark1[x]<<"\t"<<mark2[x]<<"\t"<<mark3[x]<<"\t"<<mark4[x]<<"\t"<<mark5[x]<<"\t"<<mark6[x]<<"\t"<<mark7[x]/*<<"\t"<<mark8[x]*/<<endl;
} }
system("pause");
return 0;
}
Sep 1, 2011 at 9:01am UTC
In that code, the problem is that mark8 is commented out but you try to use it anyway.
Sep 1, 2011 at 9:08am UTC
1 2 3 4 5 6 7 8 9 10
getline(indata,n);
indata>>m1;
indata>>m2;
indata>>m3;
indata>>m4;
indata>>m5;
indata>>m6;
indata>>m7;
//indata>>m8;
indata.getline (tmp,100);
1 2 3 4 5 6 7 8 9
name[size]=n;
mark1[size]=m1;
mark2[size]=m2;
mark3[size]=m3;
mark4[size]=m4;
mark5[size]=m5;
mark6[size]=m6;
mark7[size]=m7;
// mark8[size]=m8;
Look mark8 is commented.
Last edited on Sep 1, 2011 at 9:08am UTC
Sep 1, 2011 at 9:38am UTC
yes, I try out many time, but cannot work. it keep on show out
Unhandled exception at 0x5014cac0 (msvcr100d.dll) in ASSIGNMENT.exe: 0xC0000005: Access violation writing location 0xcccccccc.
Sep 1, 2011 at 9:40am UTC
opps sry, yes I commented it at mark8 because the program can get input from file until mark7.
if I put in mark8 it will show
Unhandled exception at 0x5014cac0 (msvcr100d.dll) in ASSIGNMENT.exe: 0xC0000005: Access violation writing location 0xcccccccc.
so where is the problem I did wrong?
any expert know? your help is appreciated ^^ thx
Last edited on Sep 1, 2011 at 9:42am UTC