Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Guest
May 04, 2009 May 04, 2009

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

799
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
May 04, 2009 May 04, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 04, 2009 May 04, 2009
LATEST

Hi Russ,

That is the answer I am looking for.

Thank you again.

Best regards,

Thai

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines