Use fscanf to read from given line

后端 未结 3 528
萌比男神i
萌比男神i 2021-01-22 14:40

I want read a txt file that has up to 10 lines. The file is formatted like this on all lines:

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

I\'m trying to write a f

3条回答
  •  孤街浪徒
    2021-01-22 15:09

    You were nearly done but you simply need to change the format specifier.The following code reads through the lines preceding your intended line,but ignores what it 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);
    

提交回复
热议问题