Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Skipping Bytes When Reading Files

Skipping Bytes When Reading Files

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    InflatableGarfield
    wrote on last edited by
    #1

    Hi! I have this sort of set up in my code: FILE *gen; int i; gen = fopen("data\\gen.dat", "r"); fscanf(gen, "%c", &i); Now at this point in the code the next couple of bytes are useless. How do I skip them out? I could run fscanf a couple of times but Im positive this is not the best solution. Thanks!

    S S D 3 Replies Last reply
    0
    • I InflatableGarfield

      Hi! I have this sort of set up in my code: FILE *gen; int i; gen = fopen("data\\gen.dat", "r"); fscanf(gen, "%c", &i); Now at this point in the code the next couple of bytes are useless. How do I skip them out? I could run fscanf a couple of times but Im positive this is not the best solution. Thanks!

      S Offline
      S Offline
      Scott H Settlemier
      wrote on last edited by
      #2

      fseek

      1 Reply Last reply
      0
      • I InflatableGarfield

        Hi! I have this sort of set up in my code: FILE *gen; int i; gen = fopen("data\\gen.dat", "r"); fscanf(gen, "%c", &i); Now at this point in the code the next couple of bytes are useless. How do I skip them out? I could run fscanf a couple of times but Im positive this is not the best solution. Thanks!

        S Offline
        S Offline
        shaileshkumar
        wrote on last edited by
        #3

        use seek or fseek - Shailesh

        1 Reply Last reply
        0
        • I InflatableGarfield

          Hi! I have this sort of set up in my code: FILE *gen; int i; gen = fopen("data\\gen.dat", "r"); fscanf(gen, "%c", &i); Now at this point in the code the next couple of bytes are useless. How do I skip them out? I could run fscanf a couple of times but Im positive this is not the best solution. Thanks!

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          If it's just a couple of bytes, there is nothing wrong with using an additional fscanf(). Just read the bytes into a variable named something like extra or fluff.


          "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups