[Linux-Discussion] Re: question

  • From: bobbya <bobbya@xxxxxxxxxxxx>
  • To: linux-discussion@xxxxxxxxxxxxx
  • Date: Sat, 09 Jun 2001 11:24:49 -0700

Hello,

The file is a byte code java class file,  i.e., a complied java program, so
I can't use the code below, right?
And that is what I wanted to do. I'm trying to copy a java byte code file
from one directory to another in a
C program.

while(fgets(buffer, sizeof(buffer), filePtr) != 0) )
    fprintf(writetofilePtr, "%s", buffer);
}

I figured out how to use read successfully to do it.

/** code below successfully copies the byte code file to the new file **/

n = read(sourcefd, readbuffer, numbytes);

while(n > 0) {
    write(destinationfd, readbuffer, n);
    n = read(sourcefd, readbuffer, numbytes);
}
/*********************************************************/

Now I want to use "strstr" to change a string inside the byte code when
I do the copy to the other directory.
Any hints on that? I'm working on it today, Saturday, June 9, between 11:30
am(current time) and  tonight.

Thanks,

Robert



Paul wrote:

> Curt Binder wrote:
> >
> > while(n > 0)
> >
> This should be:
> while (n!=EOF)
>
> read() will return an EOF when you try to read past the end of the
> file.  The only way to detect an EOF is to attempt reading past the end.

=============================================================
Avenir Web's Linux Discussion List

List info: //www.freelists.org/cgi-bin/webpage?webpage_id=13
To unsubscribe: email linux-discussion-request@xxxxxxxxxxxxx
with 'unsubscribe' in the Subject line.

Administrative contact: weez@xxxxxxxxxxxxx
=============================================================

Other related posts: