Friday 15 May 2015

C Read a column of a line from file -



C Read a column of a line from file -

i reading /proc/diskstats (you may or may not know it) file none less, outputs many lines , columns/fields. i'm asking if can show me how retrieve column of line. little piece of data. thanks.

i've taken look. output looks this:

8 17 sdb1 15 0 38 28 0 0 0 0 0 28 28

so have few numbers (seem long integers) , have string @ 3rd place.

now overall can read output line line. fgets standard c choice. can utilize sscanf pick out different elements. without having tested. like

sscanf(readline, "%d%s%d....", &var1, & var2 ....

should "trick" of not work combination of might seek read line strtok.

hope gives idea.

c file fgets fread fscanf

No comments:

Post a Comment