Searching strings in C++

Soldato
Joined
10 Apr 2004
Posts
13,497
Im importing a passenger data set using C++, for example, if a user wants the details of passenger ID 1, they enter 1 and they get back:

Code:
1  Neil Armstrong            American Airlines        8 30   Chicago International       AA101

Now I need it to also get the Gate Number, which is many lines further down the file. Further down there is:

Code:
Flight No.  Gate  Boarding Time

AA101       4      7 30 
HH202       2     10 00
...

What kind of command(s) should I use so that as it fgets through this part of the file it spots that the flight numbers match and that it should pull out the Gate number?

I've tried a simple
Code:
				sscanf(string, "%s %s %s %s",flight_number_2,gate,time_hours,time_mins);
				
				if(flight_number==flight_number_2){
					break;
				}
				
				printf("%s %s %s:%s\n",flight_number_2,gate,time_hours,time_mins);
			}

But unfortuantly that didn't work :p

Any hints would be nice :)

Cheers
 
not too sure if C++ is the same as C, but in C you can't compare 2 strings using ==, have to use strcmp(string1, string2), from the string.h library.
 
Back
Top Bottom