C/C++ Prog: Read 3rd Col of .txt File & Write Separate File

  • Context: Comp Sci 
  • Thread starter Thread starter kirti.1127
  • Start date Start date
Click For Summary
SUMMARY

The discussion focuses on a C/C++ program designed to read the third column from a text file and write it to a separate text file. The proposed solution involves opening the file, reading each line into a string, using a space delimiter to create a temporary array, and then writing the third value to a new file. The use of the fscanf() function is highlighted as an effective method for handling regular tabulated data. This approach is straightforward and efficient for extracting specific column data from structured text files.

PREREQUISITES
  • Understanding of C/C++ programming language syntax
  • Familiarity with file I/O operations in C/C++
  • Knowledge of string manipulation and array handling
  • Experience with the fscanf() function for reading formatted input
NEXT STEPS
  • Explore advanced file handling techniques in C/C++
  • Learn about parsing text files using regular expressions
  • Investigate the use of C++ STL containers for dynamic data storage
  • Study error handling in file operations to improve program robustness
USEFUL FOR

C/C++ developers, students learning file I/O operations, and anyone needing to manipulate and extract data from structured text files.

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.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
7K