473,396 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

modify txt file in C

hi everyone,
i met some problem in this.
i used fseek to locate position prepared to be written.
for example,
fseek(stream,16,seek_set)
then
fputs(time,stream)
while time will be users input.

the content of the txt file to be modified

aabb, ccddeeff, 30gghhiijjkk

obvious the string 30(at byte position 16)
is going to be changed.
but if users input were 3000
then gg(position 18) will be overwrote.
i will get the result
aabb, ccddeeff, 3000hhiijjkk

but all i need is

aabb, ccddeeff, 3000gghhiijjkk

or EVEN users input were 300000
i still need the result to be

aabb, ccddeeff, 300000gghhiijjkk

how to do it?
thanks
Dec 11 '07 #1
2 6934
On Dec 11, 1:10 pm, chaobre...@gmail.com wrote:
hi everyone,
i met some problem in this.
i used fseek to locate position prepared to be written.
for example,
fseek(stream,16,seek_set)
You do realize that for a text stream, the offset must either be zero,
or be the value returned by a previous successful call to ftell() on
the same stream, don't you?
then
fputs(time,stream)
while time will be users input.
[snip]
how to do it?
thanks
In a nutshell, you cannot do it with one file. While you can replace
in place data, the replacement data must be the same size as the data
to be replaced. You cannot "insert" data without overwriting other
data elements.

You will have to write your program to create a second file into which
you will copy data from the first file. You will first copy the data
prior to the data to be changed. You will then write the new data, and
finally, you will copy the data following the data to be changed. The
first file will not change; the unaffected data from the first file
will be copied to the second file, in sequence with the inserted data
Dec 11 '07 #2
ch********@gmail.com wrote:
hi everyone,
i met some problem in this.
i used fseek to locate position prepared to be written.
This is a FAQ - 12.30, and also read 19.14

And in fact, please read the FAQ entirely...

--
Mark McIntyre

CLC FAQ <http://c-faq.com/>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
Dec 11 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Chris McKeever | last post by:
I am trying to modify the Mailman Python code to stop mapping MIME-types and use the extension of the attachment instead. I am pretty much clueless as to what I need to do here, but I think I have...
4
by: pmud | last post by:
Hi I have a website (ASP.NET project using C# ) which is already put up on the server. I need to make some modification to some web pages.So the project files were copied to the a different server...
12
by: Venkat | last post by:
Greetings to All, I have the following file and i need to modify it with the contents of an array File1.txt Name Location Points Grade Venkat,Newyork,100,A Jack,LA,12,C
3
by: Maileen | last post by:
Hi, I've asked yesterday if someone already modify data into XML file using VB.NET. In fact, my XML file is like that. .... <DB> <DB_Loc>
3
by: muttu2244 | last post by:
hi everybody am trying to modify a particular string from a csv file. for ex say i have compName, ipAddr, MacAddr, Os sdfsdf , 129.122.12.34 , dsfiasdf, wsfdjhs
4
by: muttu2244 | last post by:
Hi everybody Am trying to read a csv file "temp.csv", which has the below info, compName macAddr ipAddr opSys
1
by: LB | last post by:
Hi, I want to modify my file ".vbproj". I use XML dlls of Visual Studio and that causes to modify the format of the file .vbproj and that causes problems at the compile time on another servor....
1
by: TimEl | last post by:
Hi. Using Perl, I want to modify data in an XML file and print out the entire modified file, not just the elements I modify. In CPAN I have found that XPath allows me to pinpoint the elements...
6
by: Ramesh | last post by:
Hello, I am using the ofstream class to create a text file with keys and values like: Key1=Value10 Key2=Value15 Key3=Value20 In case I need to set a new value for Key2, say value50 - I am...
2
by: letobale1982 | last post by:
Hello I would like to get some ideas on how to modify a Combobox during runtime and save the changes so next time the form is ran changes are available. Here is the plan. A form displays a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.