Hi,
I'm new here on the forum, so I will give a brief introduction. I'm a belgian student who likes programming in his spare time. Now I'm working on a school project which is actually almost finished, but I'd like to add an extra 'function'.
The idea is that I have a textfile with following content:
[startpath]=C:\testmap1\
[endpath]=C:\testmap2\test\
Now I would like to change the paths in my program (so without entering an editor and changing the code). The problem is that I can't search my textfile for the string "[endpath]=" and put my cursor after this string .
Does anybody knows the solution for my problem?
BTW, I have already managed to change the startpath by using FSEEK and FGETS, but when I tried to overwrite the path C:\testmap1\ by C:\map3\, the result was: C:\map3\ap1\. So, the last 4 characters of the previous (and longer) path stayed in the file.
Can anyone give me some tips how to easily change text in a file. I can imagine many people have already done this in configuration file or something like that...
Thanks for the help!!
[C] change content of a 'textfile
Started by skelesp, Jul 31 2008 01:46 AM
2 replies to this topic
#1
Posted 31 July 2008 - 01:46 AM
|
|
|
#2
Posted 31 July 2008 - 08:27 AM
If you read in one line at a time, you should be able to look at the initial characters in each line.
#3
Posted 31 July 2008 - 07:01 PM
Or you could (if you're using Windows) use the Windows API functions GetPrivateProfileString and SetPrivateProfileString to automatically read from and write to the file if you change it a little bit, like so:
;INI FILE FORMAT ;this is a comment ;[section] ;key=value [PATHS] start=c:\windows\blah end=c:\x\y\z


Sign In
Create Account

Back to top









