i have started writing a program to do a fast sort but on one of my builds an error is coming up and i don't know what exactly it means could you please help.

int main(void){

		

	char c[k];
		cout<<"Please enter the input filename:"<<endl;							// read in the input and output filenames
		cin>>c;

	char h[k];
		cout<<"Please enter the output filename:"<<endl;
		cin>>h;

		ifstream in(c);

	if (!in){
		cerr<<"Failed to open input file"<<c<<endl;
		exit(1);
	}//close if
	int t=0, f;
	char tempX[a], tempY[a];							// count the number of records in the file by reading them in
	int tempZ;
	while (in>>tempX>>tempY>>tempZ){
	if (t<MAX){									
		
			t+=1;
	
	
	}
	
	}
		f=t;
		in.close();			// reset the input file status after reading to the end
		in.seekg(0);		// rewind the file using seekg()
		
		friends* best= new friends [f];					// create an array (of structs) to hold all persons in the file	
		
	
	while(in){											// read the data for real this time
	if (in >> tempX>>tempY>>tempZ)
	if (t>=MAX)
		in>>tempX[t];
		in>>tempY[t];
		in>>tempZ[t];
	break;
	}
		
		
		ofstream out(h);

	if (!out){
		cerr<<"Failed to open output file"<<h<<endl;
		exit(1);
	}
		out<<"The unsorted list:"<<endl;
	for (int s=0; s<t, ++s;){
		out<<"\n\n"<<tempX[s]<<"\t\t"<<tempY[s]<<"\t\t07"<<tempZ[s]<<endl;
	}
	in.clear();
	in.close();
	out.close();		
}

the error that is coming up is due to

for (int s=0; s<t, ++s;){
		out<<"\n\n"<<tempX[s]<<"\t\t"<<tempY[s]<<"\t\t07"<<tempZ[s]<<endl;
	}

and this

while(in){											// read the data for real this time
	if (in >> tempX>>tempY>>tempZ)
	if (t>=MAX)
		in>>tempX[t];
		in>>tempY[t];
		in>>tempZ[t];
	break;
	}

and the error is error C2109: subscript requires array or pointer type.

Assuming all the other definitions are correct (e.g. defined MAX, friends etc)

The first/second problem is that tempZ is defined as an single int,
and therefore is not an array. you will need to create it as an array
e.g char tempZ[a]; to get that line to compile.

I am also guessing that you forgot that the if(t>=MAX) only refers to tempX statement and the code always reads into tempY. The in>>tempX etc. followed by reading into it.

You desperately need to write a lot less code. Say just reading in and the writing the input to the screen. Get that running and debugged then move on

I find your for-statement a little weird :for (int s=0; s<t, ++s;){
I would write this as for (int s=0; s<t; s++){
Notice the comma has dissappeared and I changed preincrement to postincrement without a ;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.