C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 6th, 2003, 01:38 PM
Icek Icek is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 7 Icek User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
truncate a file

I want to truncate a file starting from some point of it.

The code looks as follows:

FILE *f;
f=fopen("name","r+");
fseek(f,50,SEEK_SET); // for example 50 bytes from the start
// ???????? // how to trim it after setting the
// file pointer?
fclose(f);

Maybe there is a way of putting an EOF character at this point, or truncating it some other way?

Please help, thanks.

Reply With Quote
  #2  
Old July 6th, 2003, 01:48 PM
amit_t amit_t is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: India
Posts: 9 amit_t User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
dont know if putting EOF at that place will work (though if it works
then it's a better way) but there is another way...read 50 bytes
from start into a buffer ,close the file ,reopen it with "w+" &
write that buffer back into file...

HTH

Reply With Quote
  #3  
Old July 6th, 2003, 02:15 PM
Icek Icek is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 7 Icek User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
It works this way, but it is not exactly what i need. I need to hash some file before, than add to this file hash value. Then I must decompose the whole file, take the hash again and compare.

The problem is that the file structure must be identical to the original. And while reading and writing the buffer to a string, carriage return characters are not maintained, and the documents differ slightly.

Although the file compare function doesn't see the difference, the hashing function returns different results.

So, I need to trim the file, not to rewrite it.
But thanks anyway

Maybe someone knows the solution???

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > truncate a file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT