File handling

Posted on 2002-03-13
Last Modified: 2010-04-15
I have problems handling file:

1) Look at this piece of code :



File has 5 name like this :

This while loop reads till name4. then reads name5.
Now, it should stop here.
But it goes and reads name 5 again and then comes out.
I do not understand how.

2)In my program I am writing some thing into a file.
while this process is going on, I am not able to see anything written to the file using VI editor.
I am doing fflush() soon after I write to the file.
Please help
Question by:kgreddy

Accepted Solution

Sapa earned 50 total points
ID: 6861564
> This while loop reads till name4. then reads name5.
> Now, it should stop here.
> But it goes and reads name 5 again and then comes out.

Looks like it doesn't. Do you check the fscanf's return code? Looks like it read name5, and no EOF occured yet. Then it attempts to read the last chunk of data, fscanf returns error and does not modify 'name' variable. You print it (name5) again. And only now the EOF flag is raised.

> In my program I am writing some thing into a file.
> while this process is going on, I am not able to see
> anything written to the file using VI editor.

Do you restart vi after you program write? If no,
vi will show the old file content read into memory.
Use 'less' if you want to look growing files.

Expert Comment

ID: 6861978
Please do not use browser refresh after you've posted to a question.

Expert Comment

ID: 6862987
I have deleted the duplicate questions, the 3 remaining have comments.  If they have not helped, let me know which ones to delete.

Thank you
Community Support Moderator
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.


Expert Comment

ID: 6883844
             name[0] = 0x00;                                      //  or even  strcpy(name, "");

Should fix you up, which is what Sapa is alluding to, also, he is correct about vi.

I don't want any points, I just thought the example might better explain Sapa's post.

Expert Comment

ID: 6892770
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if still open in seven days.  Please post closing recommendations before that time.

Question(s) below appears to have been abandoned. Your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you. You must tell the participants why you wish to do this, and allow for Expert response.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for experts of your intention to delete and why
   --> You cannot delete a question with comments, special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the question QID/link(s) that it regards.
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process.

Please click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, to track all your open and locked questions at this site.  If you are an EE Pro user, use the Power Search option to find them.  Anytime you have questions which are LOCKED with a Proposed Answer but does not serve your needs, please reject it and add comments as to why.  In addition, when you do grade the question, if the grade is less than an A, please add a comment as to why.  This helps all involved, as well as future persons who may access this item in the future to seek help.

To view your open questions, please click the following link(s) and keep them all current with updates.

To view your locked questions, please click the following link(s) and evaluate the proposed answer.

------------>  EXPERTS:  Please leave any comments regarding your closing recommendations if this item remains inactive another seven (7) days.  Also, if you are interested in the cleanup effort, please click this link

Moderators will finalize this question if still open in 7 days, by either moving this to the PAQ (Previously Asked Questions) at zero points, deleting it or awarding expert(s) when recommendations are made, or an independent determination can be made.  Expert input is always appreciated to determine the fair outcome.
Thank you everyone.
Moderator @ Experts Exchange

P.S.  For any year 2000 questions, special attention is needed to ensure the first correct response is awarded, since they are not in the comment date order, but rather in Member ID order.

Expert Comment

ID: 6973861
Admin notified of User neglect. Force-accepted by
CS Moderator

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode ( They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question