read a line from textfile

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • friendjin
    New Member
    • Feb 2007
    • 19

    read a line from textfile

    How can I read every line from the existed file.
    eg.
    the content of textfile:
    serialnumber = " 50";
    serialfile path = "C:\\doc\\" ;
    errorfile path = "C:\\doc\\d \\";

    I want to read "50" from the first line to SeNo, read ""C:\\doc\\ "from the second line to SePath, read "C:\\doc\\d \\" ifrom the third line to ErPath.

    any idea how it can be achieved. thanks
  • kvbreddy
    New Member
    • Feb 2007
    • 23

    #2
    open file

    Loop untill EOF
    begin
    read line
    search in the line for '='
    Now copy the remaining string in to Destination.
    end

    close file

    Originally posted by friendjin
    How can I read every line from the existed file.
    eg.
    the content of textfile:
    serialnumber = " 50";
    serialfile path = "C:\\doc\\" ;
    errorfile path = "C:\\doc\\d \\";

    I want to read "50" from the first line to SeNo, read ""C:\\doc\\ "from the second line to SePath, read "C:\\doc\\d \\" ifrom the third line to ErPath.

    any idea how it can be achieved. thanks

    Comment

    • sicarie
      Recognized Expert Specialist
      • Nov 2006
      • 4677

      #3
      Originally posted by kvbreddy
      open file

      Loop untill EOF
      begin
      read line
      search in the line for '='
      Now copy the remaining string in to Destination.
      end

      close file
      And if you need help on the functions that go with kvbreddy's algorithm, I find this site to be very good with examples (I also like how they have the other functions in the library of the function (still with me?) you are looking up, off to the left of the screen).

      Comment

      • friendjin
        New Member
        • Feb 2007
        • 19

        #4
        Originally posted by kvbreddy
        open file

        Loop untill EOF
        begin
        read line
        search in the line for '='
        Now copy the remaining string in to Destination.
        end

        close file
        Hi kvbreddy;
        Thanks. the problem is I could not workout readline command, and how can I do a search.
        I would so appreciate if you could write this part of code for me.

        Comment

        • sicarie
          Recognized Expert Specialist
          • Nov 2006
          • 4677

          #5
          Originally posted by friendjin
          Hi kvbreddy;
          Thanks. the problem is I could not workout readline command, and how can I do a search.
          I would so appreciate if you could write this part of code for me.
          Sorry, but we can't do that. This is in C, right? What error messages did you get when you tried readline?

          Comment

          • friendjin
            New Member
            • Feb 2007
            • 19

            #6
            Originally posted by sicarie
            Sorry, but we can't do that. This is in C, right? What error messages did you get when you tried readline?
            Sorry about that I did not mention it. it is in VC++.
            error is identifier was not found.

            Comment

            • sicarie
              Recognized Expert Specialist
              • Nov 2006
              • 4677

              #7
              Originally posted by friendjin
              Sorry about that I did not mention it. it is in VC++.
              error is identifier was not found.
              Can you post the segment where you use readline() in your code?

              Is this written in C#? C and C# have readline functions - I don't believe C++ does... (Please anyone correct me if I'm wrong.)

              Comment

              • friendjin
                New Member
                • Feb 2007
                • 19

                #8
                Originally posted by sicarie
                Can you post the segment where you use readline() in your code?

                Is this written in C#? C and C# have readline functions - I don't believe C++ does... (Please anyone correct me if I'm wrong.)

                I actually have already worked out, but I chose another method by using strstr.

                but I do want to konw how readline works in C++.

                any ideas..thanks

                Comment

                • sicarie
                  Recognized Expert Specialist
                  • Nov 2006
                  • 4677

                  #9
                  Originally posted by friendjin
                  I actually have already worked out, but I chose another method by using strstr.

                  but I do want to konw how readline works in C++.

                  any ideas..thanks
                  That was what was confusing me. To my knowledge, readline is not in C++. (Though I could be wrong - its happened several times recently)

                  I personally prefer getline.

                  Comment

                  Working...