|
1- create a structure (or class) that contains the fields for each record ; create/use a collection that holds your records
2- in a loop :
3- read one line of the file, knowing that you know the format, you can skip unwanted lines.
4- skip line if unwanted; if line contains (is?) "============" and it's the first one, then you know it's a
new record.
5- read the next few lines to fill a record.
6- look in your collection to see if new record is already there; if it's not there, add it to your collection.
7- once you've read all the lines,
8- write back the data line-by-line in a new file.
(steps 5,6 can be optimized to not have to create a new record until you've find if the item is not in the collection).
This signature was proudly tested on animals.
|
|
|
|
|
Thanks sir your logic is to much sound.Can you give me some dummy code.Plz help me
|
|
|
|
|
I will not give you code (dummy or not); I want you to try to come up with a solution based on the suggestions we've given you.
Once you've tried one, two, or even more solutions to your problem (which sounds like a homework), and you still
have problems, then we will gladly be of help of precise problems you can still have.
It can be also easier to ask questions to your teachers and/or teaching assistants and/or computer lab assistants;
or even fellow students.
This signature was proudly tested on animals.
|
|
|
|
|
The first order of business would be to read the data into some sort of data structure. Until you can get that far, eliminating duplicates is irrelevant.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Given the struct declaration thus:
struct TestStruct
{
CObject obj[ 20 ];
};
If I say,
TestStruct *ts = new TestStruct;
Does the CRT call the constructors for any of the CObject's, either all of them, or just the first one in the array?
And does the same answer apply to calling the destructors when I delete ts ?
|
|
|
|
|
All 20 CObject default constructors will be called on creation.
Destructors will also be called on destruction.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Thanks for the reply. I am surprised, actually. I did not expect that all of them would be called.
|
|
|
|
|
They are all allocated on the stack & so gets cleaned automatically. You are almost nearly talking about something like this :
struct TestStruct
{
CObject* pObj;
TestStruct()
{
pObj = new CObject[20];
}
};
Then in the dtor you'll have to manually delete all the cobjects.
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
Don't confuse it all.
Assume we have
struct TestStruct{
CObject obj[ 20 ];
};
{
TestStruct ts;
}
{
TestStruct *ts = new TestStruct;
delete ts;
}
{
TestStruct *ts = new TestStruct;
}
|
|
|
|
|
Thanks for clearing that up.
I was confused as well.
|
|
|
|
|
I think I'm not confused.
Here[^]
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
struct TestStruct{
CObject obj[ 20 ];
};
Didn't you notice I changed my example to
struct TestStruct{
CObject* pobj;
TestStruct()
{
pObj = new CObject[20];
}
};
?
I was trying to give an example where the destructors of the CObjects wouldn't be called. What am I confusing here? Whatever may be the creating type of the TestStruct object, heap or stack, here in my example, it's going to create all the CObjects in heap.
I'll explain you better. Suppose Now you create an object of TestStruct:
TestStruct obj;
So in the destructor we have to manually delete them all.
~TestStruct()
{
delete[] pObj;
}
That's what I explained. May be you didn't get my context.
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
Easy, man! We are just talking here.
Just to be safe, I explained it all relevant to the question.
From your initial post, it was not totally clear that you meant this what you have shown here, and it is a different example from what was asked, so I just wrote it all out using the same code pattern from the initial question to avoid any possible confusion, because everything is fine as long as the person who asked the question got the right understanding not you or me.
|
|
|
|
|
|
I would expect them to be allocated on the stack IF my ts variable were a stack-based variable. But if you check my original post, you'll see that ts is allocated on the heap with new.
Are you saying that even though ts is created on the heap, that the CObject array inside the structure is created on the stack?
|
|
|
|
|
Richard Andrew x64 wrote: Are you saying that even though ts is created on the heap, that the CObject array inside the structure is created on the stack?
Exactly NOT. Actually my reply was not exactly an answer for your question. I was trying to explain the other way where it would result in a condition that you expected.
But in the reverse, I'd say, when you allocate CObjects in heap, no matter you create the TestStruct on heap or stack, they are going to remain in heap.
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
constructor: all (or better say each)
destructor: all
Why did you have trouble with that?
|
|
|
|
|
Hi,
I need some help on DateTime control, by default it will displays the current date on datetime picker. If you have changed that date to next month then i need to display one error message box.
just like for example today date is 3/2/2009 and i have selected date in datetime picker as 20/2/2009.
This is wrong right..? So i need to throw one error message box, Can any one help which event will get fired when datetime picker will changed.
I have already tried with DTN_DATETIMECHANGE, it's not working, that the event is getting executing repeatedly..
Can any one help me regarding this..?
Thanks in advance...
|
|
|
|
|
Why DTN_DATETIMECHANGE does not work for you?
It is WM_NOTIFY message and once it is fired all you need is to cast
lpChange = (LPNMDATETIMECHANGE) lParam;
and read
DWORD dwflags; // this should be GDT_VALID
and then
SYSTEMTIME st;
to see what time was selected. Then if it is month from now display a message.
|
|
|
|
|
Thanks for your answer, i am able to solve the problem..
|
|
|
|
|
Hey ppl,
I have two pointers and one value:
int* p1 = new int;
*p1 = 10;
int *p2;
p2 = p1;
Now p1 and p2 has different addresses (of course). They both points the same unnamed integer value. Lets delete p1:
delete p1;
p1 = NULL;
Now p1 is NULL and referenced the only integer is deleted. Now if I try
delete p2;
p2 = NULL;
Just crashes cause int which is referenced by p2 is not valid anymore.
So how can I check if int is still valid OR maybe make p2 = NULL when object is deleted.. I read about shared pointers with templated which are not good for me to use right now?
Any workarounds?
|
|
|
|
|
dehseth wrote: p2 = p1;
But, why one would like to do that ? Heard of need for copy c'tor and assingment operators ? Or dangling pointers ?
|
|
|
|
|
Just need it...
|
|
|
|
|
dehseth wrote: I read about shared pointers with templated which are not good for me to use right now?
In case you change your mind: shared_ptr[^] from Boost[^].
Steve
|
|
|
|
|
Nope, but thanx...
|
|
|
|