file handling
-
i am saving some data to file(CStdio class) in the following format. Address1-Description1 Address2-Description2 Address3-Description3 When ever i want to retrive data i search for the address and get the description. Now when i change the description, it is required that i replace the old description with the new one. One way is to re create the whole file again the only change of new description. This is really inefficient. Can you tell me some nice logic to do this Thanks a lot
-
i am saving some data to file(CStdio class) in the following format. Address1-Description1 Address2-Description2 Address3-Description3 When ever i want to retrive data i search for the address and get the description. Now when i change the description, it is required that i replace the old description with the new one. One way is to re create the whole file again the only change of new description. This is really inefficient. Can you tell me some nice logic to do this Thanks a lot
Hello, I don't think that it is possible to just 'insert' data in a file. When you write somewhere, data will be overwritten. You have 2 options. You can insert buffers in the file (after an address, description, insert spaces). This way, you can overwrite the description and you have the option to grow until the specified buffer size. The second option you have is to copy all the data after the description that you want to change and write it again after you update the description. If you change the description frequently, I advice option 1. This is much faster. If the changes occurr less ofter and you have lot's of addresses, I suggest the second option. This saves you a lot of space, but it takes more time when you update your file. Hope this helps. Behind every great black man... ... is the police. - Conspiracy brother Blog[^]
-
Hello, I don't think that it is possible to just 'insert' data in a file. When you write somewhere, data will be overwritten. You have 2 options. You can insert buffers in the file (after an address, description, insert spaces). This way, you can overwrite the description and you have the option to grow until the specified buffer size. The second option you have is to copy all the data after the description that you want to change and write it again after you update the description. If you change the description frequently, I advice option 1. This is much faster. If the changes occurr less ofter and you have lot's of addresses, I suggest the second option. This saves you a lot of space, but it takes more time when you update your file. Hope this helps. Behind every great black man... ... is the police. - Conspiracy brother Blog[^]
thanks for your suggestions, still i have some things to clarify. I have just 256 addresses so i will go with rewriting the file. But to do this i need to save the rest of the file temporarily, what do you think the data structure i have to use to do this. Thanks again.
-
i am saving some data to file(CStdio class) in the following format. Address1-Description1 Address2-Description2 Address3-Description3 When ever i want to retrive data i search for the address and get the description. Now when i change the description, it is required that i replace the old description with the new one. One way is to re create the whole file again the only change of new description. This is really inefficient. Can you tell me some nice logic to do this Thanks a lot
One idea would be to use a slightly different format for your file...like an .ini file.
[Addresses] Address1=Description1 Address2=Description2 Address3=Description3
You could then use GetPrivateProfileString and WritePrivateProfileString to read/change the values. Hope that helps. Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193 -
thanks for your suggestions, still i have some things to clarify. I have just 256 addresses so i will go with rewriting the file. But to do this i need to save the rest of the file temporarily, what do you think the data structure i have to use to do this. Thanks again.
Hello, First, I assume that you are using MFC's
CStdioFile
class since I don't know of a CStdio class. You can do the following:// position after the line you want to change
// read all the adresses
CList<CString> StringList;
CString sLine = "";
while( YourFileObject.ReadString(sLine) )
{
StringList.AddTail(sLine);
}/*
Change the address you want to change
Place the file pointer after the changed address
*/
// write the other address back
while( !StringList.IsEmpty() )
{
YourFileObject.WriteString(StringList.RemoveHead());
}Hope this helps :-D Behind every great black man... ... is the police. - Conspiracy brother Blog[^]