Jump to content

Read a file line by line: Difference between revisions

→‎{{header|C}}: syntax hilight
(→‎{{header|C}}: mmap method)
(→‎{{header|C}}: syntax hilight)
Line 273:
 
Implementation using mmap syscall. Works on Linux 2.6.*, should work on *BSDs (they invented mmap, after all). Line reading routine takes a callback function, each line is passed into callback as begin and end pointer. Let OS handle your memory pages, we don't need no stinking mallocs.
<lang C>#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
Line 351:
int main()
{
return read_lines("result.pssome_text_file", print_line) ? 0 : 1;
}
</lang>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.