[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]


    Search the Q&A Archives


...delete a line frm a file using c thnakx for...

<< Back to: C++ FAQ (part 1 of 10)

Question by chints
Submitted on 6/11/2004
Related FAQ: C++ FAQ (part 1 of 10)
Rating: Rate this question: Vote
how do i delete a line frm a file using c

thnakx for helping
chintan


Answer by Peedy
Submitted on 8/12/2004
Rating: Not yet rated Rate this answer: Vote
read from "1st file"
copy lines to retain (from "1st file") to "tmp file"
overwrite "1st file" with "tmp file"

 

Answer by chaithra
Submitted on 2/4/2005
Rating: Not yet rated Rate this answer: Vote
do not know

 

Answer by Undecided
Submitted on 5/8/2005
Rating: Not yet rated Rate this answer: Vote
After searching for ages for an answer to this one, I've finally found it... and I've decided I really don't like the way C handles files! ;)

4 steps:
1) Copy first part of file to a temporary file,
until you get to where you want to delete from
2) fseek() to end of that chunk
3) copy rest of the file
4) delete old file, and rename new file in its place.

It's a pain, I know... but it's the only portable way that I've seen :S

 

Answer by pappu
Submitted on 11/25/2005
Rating: Not yet rated Rate this answer: Vote
Its not possiable to delete line from c

 

Answer by FILE
Submitted on 12/1/2005
Rating: Not yet rated Rate this answer: Vote
Sucker

 

Answer by Murat Tufekci
Submitted on 3/23/2006
Rating: Not yet rated Rate this answer: Vote
   FILE *Source=fopen("db.txt","r+");
   fseek(Source,SEEK_END-sizeof(temp)-2,SEEK_END);
   fread(&temp,sizeof(temp),1,Source);
   fseek(Source,Where,SEEK_SET);
   fwrite(&temp,sizeof(temp),1,Source);
   fseek(Source,SEEK_END-sizeof(temp)-2,SEEK_END);
   _chsize(_fileno(Source),ftell(Source));

 

Answer by liyan10761
Submitted on 7/25/2006
Rating: Not yet rated Rate this answer: Vote
I do not know

 

Answer by moerderin
Submitted on 1/24/2007
Rating: Not yet rated Rate this answer: Vote
void ClipFile(LPCTSTR FileName, DWORD Position, DWORD LenToClip)
{
     SECURITY_ATTRIBUTES sa;
     memset(&sa, 0, sizeof(sa));
     HANDLE h_file = CreateFile(FileName, GENERIC_WRITE|GENERIC_READ, FILE_SHARE_READ, &sa, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
     DWORD FileSize = GetFileSize(h_file, NULL);
     HANDLE map_file = CreateFileMapping(h_file, &sa, PAGE_READWRITE, 0, 0, NULL);
     char* Data = (char*)MapViewOfFile(map_file, FILE_MAP_ALL_ACCESS, 0, 0, 0);
     memmove(Data+Position, Data+Position+LenToClip, FileSize-Position);    
     UnmapViewOfFile(Data);
     CloseHandle(map_file);
     SetFilePointer(h_file, FileSize-LenToClip, NULL, FILE_BEGIN);
     SetEndOfFile(h_file);
     CloseHandle(h_file);
}

//Example usuage:

int main(int argc, char* argv[])
{
     ClipFile("readme.txt", 3, 5);
    
     return 0;
}

 

Answer by bilal
Submitted on 2/10/2007
Rating: Not yet rated Rate this answer: Vote
use remove(*file);
function

 

Your answer will be published for anyone to see and rate.  Your answer will not be displayed immediately.  If you'd like to get expert points and benefit from positive ratings, please create a new account or login into an existing account below.


Your name or nickname:
If you'd like to create a new account or access your existing account, put in your password here:
Your answer:

FAQS.ORG reserves the right to edit your answer as to improve its clarity.  By submitting your answer you authorize FAQS.ORG to publish your answer on the WWW without any restrictions. You agree to hold harmless and indemnify FAQS.ORG against any claims, costs, or damages resulting from publishing your answer.

 

FAQS.ORG makes no guarantees as to the accuracy of the posts. Each post is the personal opinion of the poster. These posts are not intended to substitute for medical, tax, legal, investment, accounting, or other professional advice. FAQS.ORG does not endorse any opinion or any product or service mentioned mentioned in these posts.

 

<< Back to: C++ FAQ (part 1 of 10)


[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]

© 2008 FAQS.ORG. All rights reserved.