0

I am new to C++. I have a problem regarding access specified elements from a text File. I have two File containg the random sorted integert values. and an Array with some size.
For exapmle if array contain 10 elements and files will contain random number upto 10 with no element in common. such file one contain 1,4,7,8,10 then file 2 will contain rest of the elemnts 2,3,5,6,9.

My problem is how to fetch the specified elements from array and store them either file or an array.

For Example Suppose we have arr[10]= {2,4,7,3,7,8,1,7,3,1};
and file1 have elements 1,4,7,8,10 and File2 have elements 2,3,5,6,9.

so after performing operations my output arrays or text file contain
the corresponding data from array.

such as arr1[]={2,3,1,7,1} and arr2[]={4,7,7,8,3}
we can use text file also for storing these valuse........

please help me out

thanks in Advance....

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Rocky111
0

For Example Suppose we have arr[10]= {2,4,7,3,7,8,1,7,3,1};
and file1 have elements 1,4,7,8,10 and File2 have elements 2,3,5,6,9.

Arrays have a starting index of 0, so you'd have to subtract 1 from these numbers to get the actual index.

Read the numbers from your first file into an int array X, and use X[0],X[1], etc as the index of your arr[10], so arr[X[0]] would be the element corresponding to the first index listed in the first file. Do the same for an array Y read from the second file.

If you're not clear on file handling there are probably dozens of tutorials out there. Here's a good one: http://www.cplusplus.com/doc/tutorial/files/

Edited by jonsca: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.