fseek() Function | C Programming Tutorial

Поделиться
HTML-код
  • Опубликовано: 21 окт 2024

Комментарии • 24

  • @nathanaelmoh5848
    @nathanaelmoh5848 3 месяца назад

    Thanks for the great explanation. The book I'm reading says that fseek() and ftell() are not guaranteed to work with text files as with binary files so I had to come see if your channel had a video. Excellent as always. Hoping for an ftell() video soon!

  • @carlitobrigante9740
    @carlitobrigante9740 2 года назад +12

    best explanation ever sir...

  • @vinaldotambunan8117
    @vinaldotambunan8117 Год назад

    thank you sir really easy to understand love from suramadu

    • @PortfolioCourses
      @PortfolioCourses  Год назад

      You're welcome Vinaldo! :-) I'm really glad you found it easy to understand!

  • @mongraal2272
    @mongraal2272 2 года назад +5

    but why it prints only 2 asterisks intead of 4 at the end??
    Why 'j' isnt repleased by '*'?

    • @PortfolioCourses
      @PortfolioCourses  2 года назад +11

      We only print two asterisk chars with:
      fprintf(file, "**");
      So that is all we can expect to appear.
      The end of the file looks like this:
      ...
      g
      h
      i
      j


      EOF

    • @mongraal2272
      @mongraal2272 2 года назад +4

      @@PortfolioCourses thanks!!

  • @germankoga8640
    @germankoga8640 Год назад +1

    Maybe is more uncomfortable but, since the file handle is a pointer, could we do this of moving the position with pointer aritmethic too? (tho I would never)

    • @PortfolioCourses
      @PortfolioCourses  Год назад +2

      I've never tried that, I don't think that's something that can be done unless a compiler decided to support it somehow: stackoverflow.com/questions/57897105/incrementing-and-decrementing-a-file-pointer.

  • @gamingcomputers7485
    @gamingcomputers7485 11 месяцев назад

    its probably a year or 2 since this video but can we specify prefix numbers if its either text or binary like 0x15 or whatever like that? also i see that fprintf is writing to a file huh? maybe it different for binary one like fwrite?

  • @oaly3561
    @oaly3561 Год назад

    thank you for that explanation but i have a question, are there any differences between rewind() and fseek() for when you want to place cursor at the beginning?

    • @nathanaelmoh5848
      @nathanaelmoh5848 3 месяца назад

      From the Ubuntu man page for fseek: The rewind() function sets the file position indicator for the stream pointed to by stream to the beginning of the file. It is equivalent to:
      (void) fseek(stream, 0L, SEEK_SET)
      except that the error indicator for the stream is also cleared (see clearerr(3)).

  • @bbatroll
    @bbatroll 10 месяцев назад

    the goat 🐐🔥

  • @alexiszhou2103
    @alexiszhou2103 Год назад

    Hi sir, can I ask how to use ftell? As it might relate to fseek :)

    • @PortfolioCourses
      @PortfolioCourses  Год назад

      Great question Alexis. I don't have a video on ftell() yet, so maybe an online resource like this can help you in the meantime: www.tutorialspoint.com/c_standard_library/c_function_ftell.htm. :-)

  • @MonalPrakash
    @MonalPrakash 3 месяца назад

    Fseek returns 0 when operation is successful

  • @JameBold
    @JameBold Год назад

    I've often read that fseek() returns zero if it succeeds. Now I'm bit confused what is right. But thanks for the video.

    • @PortfolioCourses
      @PortfolioCourses  Год назад

      Online sources indicate that it returns zero if it succeeds too, I'll have to look into this.

    • @nathanaelmoh5848
      @nathanaelmoh5848 3 месяца назад

      @@PortfolioCourses from the Ubuntu man page for fseek: The rewind() function returns no value. Upon successful completion, fgetpos(), fseek(), fsetpos() return 0, and ftell() returns the current offset. Otherwise, -1 is returned and errno is set to indicate the error.

  • @darrenli2526
    @darrenli2526 Год назад

    thank you so much !

  • @wc3815
    @wc3815 2 года назад

    Could i ask, how do you count for if you fseek(file, -50, SEEK_END) but the file does not have any byte from 50 from the end?
    I found that c=fgetc(file) != EOF doesnt catch the error here 😭

    • @PortfolioCourses
      @PortfolioCourses  2 года назад

      It should set ferror if this occurs: en.cppreference.com/w/c/io/fseek. And then you could use ferror(file_pointer) to detect the error, e.g.: en.cppreference.com/w/c/io/ferror. :-)