LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   using fread with fscanf (https://www.linuxquestions.org/questions/programming-9/using-fread-with-fscanf-512245/)

andystanfordjason 12-20-2006 08:59 AM

using fread with fscanf
 
i would like to know if it is possible to use fread(which can read files fast) to load a file into a char buffer or similar then use fscanf or anything else to extract the formatted data? cheers

demon_vox 12-20-2006 09:20 AM

YOu mean tu read a file with fread and then parse the array with sscanf? (fscanf wil read from the file, so, dont read twice ;) ). If thats the case, sure you can.... but I dont think that it will make any difference in performance. Besides, dont asume that your program will run slow when it reads from a file. Maybe your performance problems (if any) could be somewhere else.

Cheers!

andystanfordjason 12-20-2006 09:31 AM

the problem im having is that to run fscanf over the whole file is taking a long time, memory access and writing is almost no time and i know it almost takes no time to read the whole file into a buffer. so i was thinking i could read the file into a buffer then parse that, but i dont know how!

andystanfordjason 12-20-2006 09:36 AM

oh, actually i think thats exactly what i wanted, thanks a lot

demon_vox 12-20-2006 09:49 AM

Hehe I hit the solution by the tangent :D

Cheers!


All times are GMT -5. The time now is 05:44 PM.