Read the 3rd column from a text file in C

  • Context: Comp Sci 
  • Thread starter Thread starter kirti.1127
  • Start date Start date
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 2K views
kirti.1127
Messages
10
Reaction score
0
C\C++ help needed URGENT!

I need help in C program
I have to write a c/C++ progam to read a particular column in a .txt file.
like
23.40 90.46 -129.8 -0.3
22.51 90.91 11.7 7.6
22.51 91.35 11.3 -0.0
22.06 90.46 29.1 7.8
22.06 90.91 -12.6 3.8
22.06 91.35 -49.2 -29.2
22.06 91.80 -28.7 30.6
In the abv file i have to read the third column and write in the separate .txt file.
 
Physics news on Phys.org


One simple approach:
1) Open the file and read each line to a string
2) Use space delimiter to make an temporary array
3) Make new file and write the third value
...
 


its even easier if you know the number of columns. fscanf() works great for regular tabulated data.