Find a name in struct of names

Hello. I cannot find the second name in the struct. First name comes out ok here is the code. I am reading from a file.

1
2
3
4
5
6
7
8
9
struct asma{
	char name[200];
	char birth[100];
	char death[100];
	char narrated_from[2000];
	char narrated_to[2000];
	char level[100];
	char known_for[200];
	} narrator[2];

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
int main(){
	//different variables to hold user response and file read and write
	char filename[25]="rijal.txt",fileread[2000], cont='Y', naame[200];
	ofstream writeFile;
	ifstream readFile;
	int count=0;
	
	readFile.open(filename);
	if(readFile.fail()){
		cout<<"File does not exist!"<<endl;
		cout<<"Please make sure you have put rijal.txt file and executable\n"
		     <<"file in one folder"<<endl; }
	
	
	readFile.close();
	
	
	readFile.open(filename);
	
	readFile>>noskipws;
	
	cout<<endl;
	readFile.getline(fileread,'\n');
	count=atoi(fileread);
	
	//read in to struct variable info from file
			for(int i=0;i<count;i++){//inplace of count put actual number of narrators
				readFile.getline(narrator[i].name, 200);
				
				readFile.getline(narrator[i].birth,100);	
				
				readFile.getline(narrator[i].death,100);	
				
				readFile.getline(narrator[i].narrated_from,2000);	
				
				readFile.getline(narrator[i].narrated_to,2000);	
				
				readFile.getline(narrator[i].level,100);
					
				readFile.getline(narrator[i].known_for,200);
					
			
		}
		
	readFile.clear();
	readFile.ignore();
	readFile.close();
	cout<<count<<endl;
	while(cont=='Y'){
		
		cout<<"Please enter full name to search for: ";
		//cin.ignore();
		cin.getline(naame, 200);	
		displayInfo(narrator, naame, count);}
	return 0;
	
	}	

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
void displayInfo(asma narrator[2], char Name[200], int number){
		
		int size=0,len=0;
		size=strlen(Name);
		
		for(int i=0;i<number;i++){
			//if((strcmp(narrator[i].name, name))==0){
			for(int j=0;j<size;j++){
				if(Name[j]==narrator[i].name[j]){
					len=len+1;
					cout<<len<<endl;
					}}
				if(len==size){		
					cout<<"found at record "<<i+1<<endl;
					cout<<endl;
					cout<<narrator[i].name<<endl;
					cout<<narrator[i].birth<<endl;
					cout<<narrator[i].death<<endl;
					cout<<narrator[i].narrated_from<<endl;
					cout<<narrator[i].narrated_to<<endl;
					cout<<narrator[i].level<<endl;
					cout<<narrator[i].known_for<<endl;
			}
		   else{
				cout<<"Please enter correct name. See Arabic to English\n"
				    <<"Transliteration"<<endl;
				    break;
				   
		}
	
	
}}


when I enter second name Abu Huraira I get this

Please enter full name to search for: Abu Huraira
1
2
3
Please enter correct name. See Arabic to English
Transliteration
Please enter full name to search for: 


Note that only three characters are compared but why?
Please post a small sample of your input file.

Also why are you skipping whitespace?

And why are you using all the C-strings instead of std::string, arrays instead of std::vector?

Why are you opening and closing the file several times?
ok let me try a while more
Last edited on
Topic archived. No new replies allowed.