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. Reading Files :doh:

Reading Files :doh:

Scheduled Pinned Locked Moved C / C++ / MFC
c++questioncomhelptutorial
6 Posts 5 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.
  • R Offline
    R Offline
    RedDragon2k
    wrote on last edited by
    #1

    Hello, ok my problem is that i don't know how to parse a config file. The file is read line by line into a char[255]. The config file looks like this:

    some_proberty = some_value
    test2 = test3
    url = www.codeproject.com

    So there is always the name an then = and then the value. In Visual C++ I would use CStrings which have the Trim, Left, Right Functions, etc. But it seems there are no such functions for the char. So how can I read my config file ? With best regards, Benedikt

    D R D T 4 Replies Last reply
    0
    • R RedDragon2k

      Hello, ok my problem is that i don't know how to parse a config file. The file is read line by line into a char[255]. The config file looks like this:

      some_proberty = some_value
      test2 = test3
      url = www.codeproject.com

      So there is always the name an then = and then the value. In Visual C++ I would use CStrings which have the Trim, Left, Right Functions, etc. But it seems there are no such functions for the char. So how can I read my config file ? With best regards, Benedikt

      D Offline
      D Offline
      douglasjordan
      wrote on last edited by
      #2

      Red, you may be able to use sscanf to parse each line of the file. It can parse based on a format string into the variables that are passed in the call to it. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_sscanf.2c_.swscanf.asp[^]

      R 1 Reply Last reply
      0
      • D douglasjordan

        Red, you may be able to use sscanf to parse each line of the file. It can parse based on a format string into the variables that are passed in the call to it. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_sscanf.2c_.swscanf.asp[^]

        R Offline
        R Offline
        RedDragon2k
        wrote on last edited by
        #3

        Thank you !!!!:-D

        1 Reply Last reply
        0
        • R RedDragon2k

          Hello, ok my problem is that i don't know how to parse a config file. The file is read line by line into a char[255]. The config file looks like this:

          some_proberty = some_value
          test2 = test3
          url = www.codeproject.com

          So there is always the name an then = and then the value. In Visual C++ I would use CStrings which have the Trim, Left, Right Functions, etc. But it seems there are no such functions for the char. So how can I read my config file ? With best regards, Benedikt

          R Offline
          R Offline
          Ravi Bhavnani
          wrote on last edited by
          #4

          You may find this[^] article useful. /ravi My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

          1 Reply Last reply
          0
          • R RedDragon2k

            Hello, ok my problem is that i don't know how to parse a config file. The file is read line by line into a char[255]. The config file looks like this:

            some_proberty = some_value
            test2 = test3
            url = www.codeproject.com

            So there is always the name an then = and then the value. In Visual C++ I would use CStrings which have the Trim, Left, Right Functions, etc. But it seems there are no such functions for the char. So how can I read my config file ? With best regards, Benedikt

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

            RedDragon2k wrote:

            In Visual C++ I would use CStrings which have the Trim, Left, Right Functions, etc. But it seems there are no such functions for the char.

            Sure there is. If they did not exist for char, then the CString class would not have such methods (since it is based on a char type). Why not just copy the code from the three CString methods into your project? It'll work fine.


            "Take only what you need and leave the land as you found it." - Native American Proverb

            1 Reply Last reply
            0
            • R RedDragon2k

              Hello, ok my problem is that i don't know how to parse a config file. The file is read line by line into a char[255]. The config file looks like this:

              some_proberty = some_value
              test2 = test3
              url = www.codeproject.com

              So there is always the name an then = and then the value. In Visual C++ I would use CStrings which have the Trim, Left, Right Functions, etc. But it seems there are no such functions for the char. So how can I read my config file ? With best regards, Benedikt

              T Offline
              T Offline
              ThatsAlok
              wrote on last edited by
              #6

              RedDragon2k wrote:

              ok my problem is that i don't know how to parse a config file. The file is read line by line into a char[255]. The config file looks like this:

              Two Option :- #1. Use GetPrivateProfileString() api to extract data from file #2. use CStdioFile::ReadString() method (which read the File Line by line) and then you have to parse the data manaully

              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

              cheers, Alok Gupta VC Forum Q&A :- I/ IV

              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