Bool Function(int, string) help it does not work as i want

Hello Guys,

I have like this in a file :

OK Green > start 1
OK Green > start 2
No Green > start 3

OK orange > start 1
No orange > start 2
No orange > start 3

OK red > start 1
OK red > start 2
OK red > start 3



I put each them in a array of strings called permitted group[9][5] defined globally the function readfile works fine as below.

Now the question is how can you do a function to check(I already tried !)
if(first value in the Permit_group1=="OK") &&
if(the second value in the Permit_group1=="str") && str: as in the parameters
if(the fifth value in the Permit_group1=="id") id: as in the parameters
?? how can I do that for all the 9 rows of the array


lets say I called check(1, green)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
bool check(int id, string str){

int i=0;
bool found =false;
while (i < 9 && !found){
if ((Permit_group1[i][1]==str) && (Permit_group1[i][0]=="OK") && (id== Permit_group1[i][4])){
return permit;
found=true;
}
i++;
}
return deny;

}


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
void readfile(int fileid)
{
	
char filename[ 1024 ];
sprintf( filename, "policy%d.txt", fileid);	//1
ifstream myfile (filename);
	//string stringarray[100];

	string s1;
	string s2;
	string s3;
	string s4;
	string s5;
	int i=0;
  	if (myfile.is_open()){
    cout << "Opened " << filename << " for reading." << endl;
		while (!myfile.eof())
    		{
     			myfile>>s1>>s2>>s3>>s4>>s5;
				Permit_group1[i][0]=s1;
				Permit_group1[i][1]=s2;
				Permit_group1[i][2]=s3;
				Permit_group1[i][3]=s4;
				Permit_group1[i][4]=s5;
				i++;

    		}
	}
	else{
     		cout << "There was a problem opening the file "
			<< filename
             << " for reading."
             << endl;

  	}

	myfile.close();

	for(int c=0;c<9;c++){
		for(int j=0;j<5;j++){
		
		cout<<Permit_group1[c][j]<<"   ";
		}
		cout<<endl;
	}

}

Last edited on
Topic archived. No new replies allowed.