By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,962 Members | 1,791 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,962 IT Pros & Developers. It's quick & easy.

File Editing in C

P: 1
i'm kinda new with C programming and i'm not good at it. I'm trying to make a program which involves file editing. first, a string must be searched inside the file. then edit the string in the file. i don't know how to do this in C. should i use the fgetpos() and fsetpos() functions?

any feedback will be appreciated. thanks in advance.
Jun 15 '07 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 9,197
fgetpos() and fsetpos() are for C++.

In C you use seek() and tell().

If you work directly with the file and do updates in place, be aware that the data is surrounded by the string before and the string after the one you are working on. Therefore, your edits cannot change the string length.

I suggest you read the entire file into an array of strings and then chnage the strings as needed. When you are done write the array back out to disc.
Jun 15 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.