Click here to Skip to main content
15,569,858 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi ,
i have a file .txt as below,which will be a input file


i want to read the file and keep all these attributes in a vector or array using C.
and need to iterate through the vector and append few string and write the only the attributes to a file (or save in some location,hard coding location is okay
i am a beginner to programming.Appreciate for your help.

o/p file will be as below

attr1 = somevalu1
attr2 = somevalue2

please help urgent!!!
Updated 10-Mar-15 11:46am
Sergey Alexandrovich Kryukov 10-Mar-15 16:47pm    
Vector? Did you mean C++ then, not C? :-)

No it's not urgent. And you can learn about file handling at any of the following links:[^].
Share this answer
Please see:[^],[^].

Note that C arrays are of fixed size. Even though you can resize the vector, this is actually reallocation, which is not reasonable efficient:[^],[^].

Therefore, it would be much better to change the file format and write the number of records (lines, whatever it is) in first line, as well as all other metadata you may need. This "prefix" approach is much more efficient, as you can allocate array memory only once, in the very beginning.

See also:[^].

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900