Having problem working with DAT files!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mojtabasah
    New Member
    • Jan 2007
    • 2

    Having problem working with DAT files!

    I want to know if there is any function in that reads a whole line from a file each time I use it. The file format is txt.
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    What methods are you using now instead of reading the entire line? Reading an entire line is the same as reading each char until you reach a '\n' or whatever Microsoft's version of a '\n' is.

    Comment

    • mojtabasah
      New Member
      • Jan 2007
      • 2

      #3
      Originally posted by RedSon
      What methods are you using now instead of reading the entire line? Reading an entire line is the same as reading each char until you reach a '\n' or whatever Microsoft's version of a '\n' is.
      Thanks for replying.You mean I use a loop, get one character a time, concatinate them to a string until I reach a '\n' ?
      Is there any simpler way for doing that?

      Comment

      • RedSon
        Recognized Expert Expert
        • Jan 2007
        • 4980

        #4
        Yes, it depends on what libraries you want to use, or what your instructor allows. If it is an exercise in using file streams and reading bytes into strings I expect a loop will be your only answer.

        Comment

        • horace1
          Recognized Expert Top Contributor
          • Nov 2006
          • 1510

          #5
          Originally posted by RedSon
          What methods are you using now instead of reading the entire line? Reading an entire line is the same as reading each char until you reach a '\n' or whatever Microsoft's version of a '\n' is.
          you can use fgets() in C
          http://www.cplusplus.c om/reference/clibrary/cstdio/fgets.html

          and getline() in C++
          http://www.cplusplus.c om/reference/iostream/istream/getline.html

          Comment

          • diSangro
            New Member
            • Jan 2007
            • 69

            #6
            Example of how to use fgets/fputs(C code), function readin a line from stdin and send it to stdout , no loops:

            int mygetline(char *line, int max)
            {
            if(fgets(line,m ax,stdin)==NULL ) return 0;
            else {fputs(line,std out);
            return 1;
            }
            }



            Originally posted by mojtabasah
            Thanks for replying.You mean I use a loop, get one character a time, concatinate them to a string until I reach a '\n' ?
            Is there any simpler way for doing that?

            Comment

            Working...