c - Use fscanf to read from given line -


i want read txt file has 10 lines. file formatted on lines:

1 1 8 2 2 3 3 1 15 4 2 7 

i'm trying write function read line provided int passed it. thought of using loop iterate through lines without scanning can't figure out how implement that.

my function far looks this, loop has not been implemented yet.

void process(int linenum, char *fullname)   {     int ii, num1, num2, num3;      file* f;      f = fopen(fullname, "r");      if(f==null)        {       printf("error: not open %s", fullname);       }      else     {     (ii=0 (ii = 0; ii < (linenum-1); ii++)       {       /*move through lines without scanning*/       fscanf(f, "%d %d %d", &num1, &num2, &num3);       }      printf("numbers are: %d %d %d \n",num1, num2, num3);     }   } 

you done need change format specifier.the following code reads through lines preceding intended line,but ignores reads.

for (ii=0 (ii = 1; ii < (linenum-1); ii++)       {       /*move through lines without scanning*/       fscanf(f, "%*d %*d %*d%*c");       // fscanf(f, "%*d %*d %*d\n");       } fscanf(f,"%d%d%d",&num1,&num2,&num3); 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

How can I fetch data from a web server in an android application? -

jquery - How can I dynamically add a browser tab? -