anyone know a good tutorial for searching a file, its a text fle and i need to search for aspects of the file. its a flight database and i need to search for flight numbers, routes and flight times mainly
anyone know a good tutorial for searching a file, its a text fle and i need to search for aspects of the file. its a flight database and i need to search for flight numbers, routes and flight times mainly
Last edited by chris285; 04-19-2005 at 07:29 AM.
Read in the file to different buffers and then do the search.
You have to look for common elements of the things you are looking for, like do the flight numbers have a consistent prefix.
Or if you file is delimited and has fields you can read in a line and search through for the correct field and read it into a buffer.
Or if your file has a fixed record length and field lengths you can read in a record at a time and look for the specific bytes that hold the info you need.
Compiler == Visual C++ 6.0"Come Out Fighting."
On the Win32 platform, one solution is file-mapping.
Kuphryn
having a problem with reading the file into the buffer and it displaying it, this is what i have so far
Code:int Cfunctions::Flightdetails() { cout << "Please enter flight number" << endl; cin >> flightno; system("cls"); ifstream file; file.open("flight.txt",ios::nocreate); if(!file) { cout<<"UNABLE TO OPEN FILE!!"; goto end; } while(file) n = 1; file.get(ch); char outputting[57]; outputting[n] = ch; n++; cout << outputting << endl; if(ch=='~') { ch=NULL; } if(ch=='#') { ch=NULL; } end: file.close(); return 0; }
Try replacing NULL with '\0' or just 0. NULL is a specific address that is gauranteed to exist, not the null char, which has the integer value of zero, 0. Since zero can be confused with capital Oh, I feel it is best to be explicit and use the char description of the null char, which is '\0'.
Also, put the checks for '~' and '#' before the lines you use to append ch to the buffer.
You're only born perfect.
It also looks like you're missing braces around your while loop (it will probably infinite loop)
And get rid of the goto statement and just put 'return 1'(or some error code) unless you plan on adding more code at the end of the function (in which case there may still be a better solution than goto). The file should also implicitly close when the ifstream goes out of scope at the end of the function.
"Think not but that I know these things; or think
I know them not: not therefore am I short
Of knowing what I ought."
-John Milton, Paradise Regained (1671)
"Work hard and it might happen."
-XSquared