C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28629
Number of posts: 94611

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
read() function on unix Posted by AndreyP on 20 Mar 2004 at 6:14 AM
Hi ,
I have a problem with the read function. i have a loop wich reads a text file charcter by character and in some point i duplicate the file descriptor (dup function) and pass it to another function. The problem starts when the other function finishes it work. Since than my filedesriptor doesn't change when i read from a file and i am stuck on the same character.
Help !!!
Report
Re: read() function on unix Posted by DB1 on 20 Mar 2004 at 6:33 AM
: Hi ,
: I have a problem with the read function. i have a loop wich reads a text file charcter by character and in some point i duplicate the file descriptor (dup function) and pass it to another function. The problem starts when the other function finishes it work. Since than my filedesriptor doesn't change when i read from a file and i am stuck on the same character.
: Help !!!
:

Post some of your problematic code.


To understand recursive, first you need to understand recursive

Report
Re: read() function on unix Posted by AndreyP on 20 Mar 2004 at 7:48 AM
the function is really long so i will give you the highlights:
this is the main loop:

do
{
if((ssBytesRead=read(fp,input,BUFFER_SIZE)))
{
...
fp=lseek(fp,-1*total_read,SEEK_CUR);
...
here i call the second function with the duplicate fp:
get_token_value(dup(fp));
}

}while(ssBytesRead!=0);

the get_token value function reads the text the same way the main loop does (using the read function) and at the end just before return it moves the fp one step back (using lseek).
After that the file pointer in the main loop won't move even as a result of read.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.