linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Markus Rechberger <mrechberger@gmail.com>
To: fabio <fabio@crearium.com>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: lseek question
Date: Sun, 6 Nov 2005 03:04:39 +0100	[thread overview]
Message-ID: <d9def9db0511051804m1f443b00x89a655efc503f0b8@mail.gmail.com> (raw)
In-Reply-To: <436D5913.504@crearium.com>

Hi Fabio,

On 11/6/05, fabio <fabio@crearium.com> wrote:
> Hello people,
>
> What's wrong with this code:
>
> -bash-3.00$ cat lseek.c ; wc -l datafile ; gcc lseek.c ; ./a.out 1000
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> main(int argc, char *argv[])
> {
>         FILE *fp;
>         int offset=atoi(argv[1]);
>         fp=fopen("datafile","r");
>         lseek(fp,offset,SEEK_SET);

regarding man lseek
off_t lseek(int filedes, off_t offset, int whence);
it requires an integer filehandle, FILE *fp is not an integer!

you're probably looking for fseek

       int fseek( FILE *stream, long offset, int whence);
       long ftell( FILE *stream);
       void rewind( FILE *stream);
       int fgetpos( FILE *stream, fpos_t *pos);
       int fsetpos( FILE *stream, fpos_t *pos);

hope this helps,
Markus

      reply	other threads:[~2005-11-06  2:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-06  1:14 lseek question fabio
2005-11-06  2:04 ` Markus Rechberger [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d9def9db0511051804m1f443b00x89a655efc503f0b8@mail.gmail.com \
    --to=mrechberger@gmail.com \
    --cc=fabio@crearium.com \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).