File Handling

Reply

Join Date: Dec 2007
Posts: 205
Reputation: carobee is an unknown quantity at this point 
Solved Threads: 11
carobee carobee is offline Offline
Posting Whiz in Training

File Handling

 
0
  #1
Dec 14th, 2007
hi,

i wanted some help in File handling in C. consider i have one File like a.txt
a.txt

[Marks]

Physics = 60
Chemistry = 80 ;Prac(25)
Maths = 98

[Grade]

Neatness = B
Attention = A ;A+(9.5)

Now suppose i have to insert new values in this file for the subjects or maybe for Grades, then what logic am i suppose to follow?
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 514
Reputation: Jishnu will become famous soon enough Jishnu will become famous soon enough 
Solved Threads: 26
Jishnu's Avatar
Jishnu Jishnu is offline Offline
Posting Pro

Re: File Handling

 
0
  #2
Dec 14th, 2007
Do you want to insert one more record to the file or do you want to modify the current values? In any case please mention how you've approached the problem uptil now.
"You know you're a computer geek when you try to shoo a fly away from the monitor screen with your cursor. That just happened to me. It was scary." - Juuso Heimonen.

"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 205
Reputation: carobee is an unknown quantity at this point 
Solved Threads: 11
carobee carobee is offline Offline
Posting Whiz in Training

Re: File Handling

 
0
  #3
Dec 14th, 2007
i want to modify the current values. i feel i should first read the file upto some size into a buffer then in that buffer search for Marks (strstr). after that agn search for Physics in the same way
please correct me if im wrong
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 514
Reputation: Jishnu will become famous soon enough Jishnu will become famous soon enough 
Solved Threads: 26
Jishnu's Avatar
Jishnu Jishnu is offline Offline
Posting Pro

Re: File Handling

 
0
  #4
Dec 14th, 2007
You are right. Have you tried to code such functions? Please post them over here using code tags.
"You know you're a computer geek when you try to shoo a fly away from the monitor screen with your cursor. That just happened to me. It was scary." - Juuso Heimonen.

"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 205
Reputation: carobee is an unknown quantity at this point 
Solved Threads: 11
carobee carobee is offline Offline
Posting Whiz in Training

Re: File Handling

 
0
  #5
Dec 14th, 2007
no i haven't and want help in this regard
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 514
Reputation: Jishnu will become famous soon enough Jishnu will become famous soon enough 
Solved Threads: 26
Jishnu's Avatar
Jishnu Jishnu is offline Offline
Posting Pro

Re: File Handling

 
1
  #6
Dec 14th, 2007
You are surely not going to get anyone to write the entire code for you. You know how to do the task. Separate it into several small manageable modules. Write the algorithm in a logical order. Refering to each step in the algorithm, write the corresponding C language statements. After you've written the entire code, compile/run it. Try to debug the errors if any. If you are unable to do so, you will definitely get help from this forum. I don't see in what other way I can help you. Please mention if this is not what you were looking for. In that case you need to be more specific with the kind of help you want.
"You know you're a computer geek when you try to shoo a fly away from the monitor screen with your cursor. That just happened to me. It was scary." - Juuso Heimonen.

"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 205
Reputation: carobee is an unknown quantity at this point 
Solved Threads: 11
carobee carobee is offline Offline
Posting Whiz in Training

Re: File Handling

 
0
  #7
Dec 17th, 2007
i am able to extract from file. For eg lets take [Marks] Physics = 60
i am able to extract upto =60, but nw my problem lies that i am not able to replace with new value. how do i do that?
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: File Handling

 
0
  #8
Dec 17th, 2007
Line 60 is wrong in your code, and lines 88-92 are close....
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 205
Reputation: carobee is an unknown quantity at this point 
Solved Threads: 11
carobee carobee is offline Offline
Posting Whiz in Training

Re: File Handling

 
0
  #9
Dec 17th, 2007
i havn't given any of the code. which code r u talking abt?
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 241
Reputation: ssharish2005 is on a distinguished road 
Solved Threads: 20
ssharish2005's Avatar
ssharish2005 ssharish2005 is offline Offline
Posting Whiz in Training

Re: File Handling

 
0
  #10
Dec 17th, 2007
on what i know so far, u cant update the contents directly on to the file (well perhaps u can). Perhaps what i would suggest is read each line from the source file into a string. i.e line by line. See if u need to make some changes in that line. IF so do that changes in the string, and write that string back to a new file. And follow the same for all the lines in the source file and keep on copying it on to the new file. Once u have reached EOF on you old file. Delete the old file and rename the new file to the old filename.

That makes it easy for you.

ssharish
Last edited by ssharish2005; Dec 17th, 2007 at 3:45 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC