Thursday, 15 April 2010

c - How to control the data content of a file using the Linux system call read() ? -



c - How to control the data content of a file using the Linux system call read() ? -

i have file of integers separated newline character such as:

277 123 456 . . . etc

i able read file contents , store in array buffer using read() linux scheme phone call such

// open file filedesc = open(filename,o_rdonly); // read file if opened read(filedesc, buffer, max_buff_size)

i have more goes when utilize printf (%c format) view content of buffer storing file contents as,

buffer[0] = 2 buffer[1] = 7 buffer[2] = 7 buffer[3] = buffer[4] = 1 buffer[5] = 2 buffer[6] = 3 . . etc

i wanted each buffer index hold entire value before each \n such as

buffer[0] = 277 buffer[1] = 123 buffer[2] = 456 . . etc.

is there way can command way read() scheme phone call stores file content buffer? or there improve alternative task?

thanks.

you have improve success buffered c stdio library. here's basic code need:

#include <stdio.h> file *fp; int n; fp = fopen(filename, "r"); if (fp == null) ... // error, not open while (fscanf(fp, "%d", &n) == 1) { printf("n = %d\n", n); }

c linux system-calls readfile

No comments:

Post a Comment