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. How to read .txt file and find delimiter ?

How to read .txt file and find delimiter ?

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
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.
  • M Offline
    M Offline
    mathivanaan
    wrote on last edited by
    #1

    Hi I try reading file through windows programming in vc++. My code like

    DWORD wmWritten;
    char strVal[1024];
    dir = CreateFile(textBuffer,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
    ReadFile(dir,strVal,1024,&wmWritten,NULL);

    textBuffer is my input file. i got all lines from text file. But want find some delimiter or i want return particular line text or (delimiter line text) Please give idea or sample code Regards, M.Mathivanan

    L A D 3 Replies Last reply
    0
    • M mathivanaan

      Hi I try reading file through windows programming in vc++. My code like

      DWORD wmWritten;
      char strVal[1024];
      dir = CreateFile(textBuffer,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
      ReadFile(dir,strVal,1024,&wmWritten,NULL);

      textBuffer is my input file. i got all lines from text file. But want find some delimiter or i want return particular line text or (delimiter line text) Please give idea or sample code Regards, M.Mathivanan

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, you could scan the input, i.e. have a loop look at each of the characters in strVal after you filled it (make sure to use the return value of ReadFile as there may be less than 1024 characters read). it would be easier to use some higher-level I/O functions. Assuming you want C code, you could use fopen(), fread(), or better yet fgetline(). Look them up in your C book and in MSDN. And always check the return value you get from almost all Windows or C functions. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

      1 Reply Last reply
      0
      • M mathivanaan

        Hi I try reading file through windows programming in vc++. My code like

        DWORD wmWritten;
        char strVal[1024];
        dir = CreateFile(textBuffer,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
        ReadFile(dir,strVal,1024,&wmWritten,NULL);

        textBuffer is my input file. i got all lines from text file. But want find some delimiter or i want return particular line text or (delimiter line text) Please give idea or sample code Regards, M.Mathivanan

        A Offline
        A Offline
        Adam Roderick J
        wrote on last edited by
        #3

        try strtok http://www.cplusplus.com/reference/clibrary/cstring/strtok/[^]

        Величие не Бога может быть недооценена.

        1 Reply Last reply
        0
        • M mathivanaan

          Hi I try reading file through windows programming in vc++. My code like

          DWORD wmWritten;
          char strVal[1024];
          dir = CreateFile(textBuffer,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
          ReadFile(dir,strVal,1024,&wmWritten,NULL);

          textBuffer is my input file. i got all lines from text file. But want find some delimiter or i want return particular line text or (delimiter line text) Please give idea or sample code Regards, M.Mathivanan

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

          mathivanaan wrote:

          But want find some delimiter...

          Have you tried strchr()?

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "Man who follows car will be exhausted." - Confucius

          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