Skip to main content
May 4, 2009
Question

How to write a function read line from a file in FDK?

  • May 4, 2009
  • 2 replies
  • 794 views

Hello,

I want to write a function that can read a file in line by line in FDK. How do I write it. If FDK could not. Is there any the way? Please help.

Thank you,

Thai Nguyen

    This topic has been closed for replies.

    2 replies

    May 4, 2009

    Hi Russ,

    That is the answer I am looking for.

    Thank you again.

    Best regards,

    Thai

    Legend
    May 4, 2009

    Thai,

    You can use the "channel" functions for this. I'm far from an expert on channel programming but I've read files line-by-line successfully by going one character at a time, looking for a carriage return.

    You can open up the file channel with something like:

      ChannelT chan;
     
      FilePathT *path;
     
      UCharT ptr[1];
     
      IntT numRead;

      path = F_PathNameToFilePath("C:\\temp\\mydoc.txt", NULL, FDefaultPath);
      if((chan = F_ChannelOpen(path,"r")) == NULL)
          return;

      //read the first character
      numRead = F_ChannelRead(ptr, sizeof(UCharT), 1, chan);

    ...then you can call F_ChannelRead iteratively to build the string in a buffer, looking for a carriage return (ASCII 13) and stopping there. (that is, ptr[0] == 13).

    There might be a better way. This is just the way I've gotten it to work. It probably is not a good method for unicode files.

    Russ