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. Pointer in a .txt file?

Pointer in a .txt file?

Scheduled Pinned Locked Moved C / C++ / MFC
databaseperformancehelptutorialquestion
3 Posts 3 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi The following information is in a .txt file. I nead to read through it, pick out certain parts and send the information to a DB. Memory SM, location 1 Name: John Doe Number: +12345 Memory SM, location 2 Name: Jane Doe Number: +54321 Memory SM, location 3 Name: Jack Doe Number: +112233 ... Here is the code I use to get the info I need from the first 3 lines: /***********************************************/ FILE *stream; stream = fopen( "number", "r" ); char bufLine1[30], bufLine2[30], bufLine3[30]; fgets(bufLine1, 30, stream); fgets(bufLine2, 30, stream); fgets(bufLine3, 30, stream); fclose( stream ); char *pNext1 = &bufLine1 [21]; char *pNext2 = &bufLine2 [9]; char *pNext3 = &bufLine3 [11]; strcpy(bufLine1, pNext1); strcpy(bufLine2, pNext2); strcpy(bufLine3, pNext3); //information sent to database /***********************************************/ Is there a way that I can put this in a loop and then start reading the 4th, 5th & 6th line and send their details off to the DB. And the go on to the 7th, 8th & 9th etc? I persume it's something like a pointer in a text file but I'm not sure how to do this. Thanks for any help. Alan

    A W 2 Replies Last reply
    0
    • L Lost User

      Hi The following information is in a .txt file. I nead to read through it, pick out certain parts and send the information to a DB. Memory SM, location 1 Name: John Doe Number: +12345 Memory SM, location 2 Name: Jane Doe Number: +54321 Memory SM, location 3 Name: Jack Doe Number: +112233 ... Here is the code I use to get the info I need from the first 3 lines: /***********************************************/ FILE *stream; stream = fopen( "number", "r" ); char bufLine1[30], bufLine2[30], bufLine3[30]; fgets(bufLine1, 30, stream); fgets(bufLine2, 30, stream); fgets(bufLine3, 30, stream); fclose( stream ); char *pNext1 = &bufLine1 [21]; char *pNext2 = &bufLine2 [9]; char *pNext3 = &bufLine3 [11]; strcpy(bufLine1, pNext1); strcpy(bufLine2, pNext2); strcpy(bufLine3, pNext3); //information sent to database /***********************************************/ Is there a way that I can put this in a loop and then start reading the 4th, 5th & 6th line and send their details off to the DB. And the go on to the 7th, 8th & 9th etc? I persume it's something like a pointer in a text file but I'm not sure how to do this. Thanks for any help. Alan

      A Offline
      A Offline
      Albert Pascual
      wrote on last edited by
      #2

      Yes, just don't close the stream and do a while(EOF)! Cheers Al

      1 Reply Last reply
      0
      • L Lost User

        Hi The following information is in a .txt file. I nead to read through it, pick out certain parts and send the information to a DB. Memory SM, location 1 Name: John Doe Number: +12345 Memory SM, location 2 Name: Jane Doe Number: +54321 Memory SM, location 3 Name: Jack Doe Number: +112233 ... Here is the code I use to get the info I need from the first 3 lines: /***********************************************/ FILE *stream; stream = fopen( "number", "r" ); char bufLine1[30], bufLine2[30], bufLine3[30]; fgets(bufLine1, 30, stream); fgets(bufLine2, 30, stream); fgets(bufLine3, 30, stream); fclose( stream ); char *pNext1 = &bufLine1 [21]; char *pNext2 = &bufLine2 [9]; char *pNext3 = &bufLine3 [11]; strcpy(bufLine1, pNext1); strcpy(bufLine2, pNext2); strcpy(bufLine3, pNext3); //information sent to database /***********************************************/ Is there a way that I can put this in a loop and then start reading the 4th, 5th & 6th line and send their details off to the DB. And the go on to the 7th, 8th & 9th etc? I persume it's something like a pointer in a text file but I'm not sure how to do this. Thanks for any help. Alan

        W Offline
        W Offline
        wangyiming
        wrote on last edited by
        #3

        1. whether the length of bufLine1 is more than 22, if not, the pointer(pNext1) maybe is out of control 2. you can use substr function

        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