Reading in a specific column of data from a text file in C

前端 未结 4 999
说谎
说谎 2020-12-04 02:56

My text file looks like this:

987 10.50   N   50
383 9.500   N   20
224 12.00   N   40

I want to read only the second column of data. How w

4条回答
  •  感动是毒
    2020-12-04 03:36

    C89/C90 has the function strtok that could be used to read the file line by line, separate the columns with the "space" delimiter and then you could access the nth token (representing the nth column in that row in the file).

    strtok is declared in

    http://cplusplus.com/reference/cstring/

    Some implementations also have a thread-safe re-entrant version called strtok_r.

提交回复
热议问题