Deleting a line in a text file
-
Please help me!!! Can any one tell me how to delete a line in text file. Please tell me how to do it in C (not MFC, C++) Thanks... If you have faith in the cause and the means and in God, the hot Sun will be cool for you.
-
Please help me!!! Can any one tell me how to delete a line in text file. Please tell me how to do it in C (not MFC, C++) Thanks... If you have faith in the cause and the means and in God, the hot Sun will be cool for you.
You can't. What you have to do is read the file in memory, erase the line and write the complete file back. An alternative is to open a temporary file, write line by line in it (except for the line you want to remove), delete your original file and then rename your new file.
Cédric Moonen Software developer
Charting control -
You can't. What you have to do is read the file in memory, erase the line and write the complete file back. An alternative is to open a temporary file, write line by line in it (except for the line you want to remove), delete your original file and then rename your new file.
Cédric Moonen Software developer
Charting controlI cannot take big data inside memory because I may have 1 Lakh records to be written to the file. I cannot also use temp file because I may to exchange data from original file to temp file alteast 50,000 times. If you have faith in the cause and the means and in God, the hot Sun will be cool for you.
-
I cannot take big data inside memory because I may have 1 Lakh records to be written to the file. I cannot also use temp file because I may to exchange data from original file to temp file alteast 50,000 times. If you have faith in the cause and the means and in God, the hot Sun will be cool for you.
you 'll have to BTW, because there's no other way to do it
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
I cannot take big data inside memory because I may have 1 Lakh records to be written to the file. I cannot also use temp file because I may to exchange data from original file to temp file alteast 50,000 times. If you have faith in the cause and the means and in God, the hot Sun will be cool for you.
There is no way of doing that. Mmmh, I think there is problem with your design: if you have to update files so many times, I don't think this is the right choice. Can't you use a database for that ? What is the purpose of this file exactly ?
Cédric Moonen Software developer
Charting control -
There is no way of doing that. Mmmh, I think there is problem with your design: if you have to update files so many times, I don't think this is the right choice. Can't you use a database for that ? What is the purpose of this file exactly ?
Cédric Moonen Software developer
Charting controlRequirement is we have to query data from database and modify the recordsets and write the data into the text file. If you have faith in the cause and the means and in God, the hot Sun will be cool for you.
-
I cannot take big data inside memory because I may have 1 Lakh records to be written to the file. I cannot also use temp file because I may to exchange data from original file to temp file alteast 50,000 times. If you have faith in the cause and the means and in God, the hot Sun will be cool for you.
An optimization is to write the remaining file from the point of the deleted data rather than the entire file.
Bahadur - yar - Jung wrote:
I cannot take big data inside memory because I may have 1 Lakh records to be written to the file.
Use buffered IO
"What classes are you using ? You shouldn't call stuff if you have no idea what it does"
Christian Graus in the C# forumled mike