Hi
I have problem with comparison when input new staff info to binary file:
For exp: I have a info.text containing
name[tab]title[tab]position[tab]phone number [tab] ID
This file already transfered to info.dat.
Now , I want to append this binary file info.dat by adding new staff until
i need to take note that ID , as long as the ID is as same as (case sensitive)
the one in the staff info.dat , it will continue to ask user to input a new unique
ID.
How do I do that ?
Can I use stricm() function to compare ? And How do I compare between user-key-in
to the info inside the binary info.dat?
assuming I have constructed struct Staff{name, tittle...);
Thanks.:pinguin:
7 replies to this topic
#1
Posted 18 October 2011 - 07:54 AM
|
|
|
#2
Posted 18 October 2011 - 04:52 PM
C or C++? In C you can use strcmp function to compare cstrings, in C++ you have == operator (for std::string).
A conclusion is where you got tired of thinking.
#define class struct // All is public.
#3
Posted 18 October 2011 - 04:55 PM
its C++ , can you tell me abit more about == operator , thx.
#4
Posted 18 October 2011 - 05:58 PM
It works the same as comparing, lets say, integers:
std::string s1("test");
std::string s2("test");
if (s1 == s2)
std::cout << "both strings match";
A conclusion is where you got tired of thinking.
#define class struct // All is public.
#5
Posted 18 October 2011 - 10:39 PM
But how do I compare between user-key-in and the date inside the dat file?
#6
Posted 19 October 2011 - 04:23 AM
Ask user to provide data and read data from file, then compare them.
A conclusion is where you got tired of thinking.
#define class struct // All is public.
#7
Posted 19 October 2011 - 09:46 AM
So everytime you get new input, you scan the entire binary file for a matching id, if none found you add new staff member, if not you ask them to re-enter the idnum. Is this the approach you must use?
Perfection of means and confusion of ends seem to characterize our age. Albert Einstein :confused:
#8
Posted 19 October 2011 - 05:24 PM
Yea, thats what I want , but not the code :crying:
cout << "Email: " ;
cin >> ID_input;
while(strcmp(s.id,ID_input)==0)
{
file.read(reinterpret_cast <char*> (&s), sizeof(s));
cout << "Email exists, re-type antother one"<< endl;
cout << "Email : " ;
cin >> ID_input;
strcpy(s.id,ID_input);
}
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









