Computer Science Canada database question |
Author: | JR [ Thu Jan 20, 2005 6:08 pm ] |
Post subject: | database question |
k lets say i got struct movies{ int year; char title[256]; char director[256]; char genere[256] char actors[256]; }; movies entery; how do i search inside the structure for a specifit title, year actors ect? lets say i type like 20 records inside a file using one strcutre. then i want to search the name lord of the rings as the title in all of those records and then if it finds it it ouputs all the titles with this name and then allows the user to choose one and edit it. how to do it? The records are stored inside a file. |
Author: | wtd [ Thu Jan 20, 2005 6:33 pm ] | ||
Post subject: | |||
Is this C or C++? If it's the latter, I suggest you use the standard library a bit more and take advantage of the ability to have member functions. Something like:
|
Author: | Andy [ Thu Jan 20, 2005 6:41 pm ] | ||
Post subject: | |||
im not sure i understand ur question exactly.. but what i think ur getting at is this
not sure if that helps ![]() |
Author: | wtd [ Thu Jan 20, 2005 6:53 pm ] | ||||
Post subject: | |||||
Andy wrote: im not sure i understand ur question exactly.. but what i think ur getting at is this
not sure if that helps ![]() If you're forced to use C, then I highly recommend using strncpy to avoid buffer overflows.
But then, string handling is probably the number one reason C is a horrible language for a newbie. |
Author: | Andy [ Thu Jan 20, 2005 7:16 pm ] |
Post subject: | |
what does strncpy do? |
Author: | wtd [ Thu Jan 20, 2005 7:23 pm ] |
Post subject: | |
Andy wrote: what does strncpy do?
It's simply limits the number of characters copied. http://man.he.net/man3/strncpy |
Author: | JR [ Thu Jan 20, 2005 8:01 pm ] |
Post subject: | |
hmm ok, i still dont know how to do a search. i dont want to complicated the program too much and its C++. |
Author: | wtd [ Thu Jan 20, 2005 8:17 pm ] | ||||
Post subject: | |||||
JR wrote: hmm ok, i still dont know how to do a search. i dont want to complicated the program too much and its C++.
http://www.msoe.edu/eecs/cese/resources/stl/string.htm The find method does what you want. Note that I also go to the effort of lower-casing both the title and the search string, so you get a case-insensitive search.
|
Author: | Andy [ Thu Jan 20, 2005 8:40 pm ] |
Post subject: | |
what complier are you using? maybe i can post some of my databases so u can take a look |
Author: | wtd [ Thu Jan 20, 2005 8:46 pm ] |
Post subject: | |
Andy wrote: what complier are you using? maybe i can post some of my databases so u can take a look
I'm using G++, but that code will work with any standards-compliant C++ compiler. |
Author: | Andy [ Thu Jan 20, 2005 8:46 pm ] |
Post subject: | |
o not you wtd lol.. u dont need to see my crappy programs, i was talking to JR |
Author: | JR [ Thu Jan 20, 2005 10:40 pm ] |
Post subject: | |
devC++ |
Author: | Andy [ Fri Jan 21, 2005 7:54 am ] |
Post subject: | |
Ooo.. i dont think my code will work then.. but you can take a look just the same... here i'll post the exe version too, see insdie of going through the list one by one, i used a binary tree to sort my contacts.. i dont know how much u noe about them, but they're quite useful dl |
Author: | wtd [ Fri Jan 21, 2005 4:24 pm ] |
Post subject: | |
Note: if you're trying to demonstrate how you solved a problem, the executable version tells people very very little. |
Author: | Andy [ Sat Jan 22, 2005 3:12 pm ] |
Post subject: | |
thats y the source is attatched too under the dl link |