For example, I code :
fp = popen("wc -l < myfile", "r");
But myfile
should be any file's name which is parsed to this project. It could be file abc.txt
or 123.txt
or xy.txt
etc.
Then I want to get the output of executing this wc -l < myfile
. But the problem is that I don't know which function in C can help me to parse the name of the myfile
to this shell command and I can also get the output.
Can anyone gives me some suggestions?
Edit:
The file I want to read is very large. I want to read its data into an array.I cannot use list to store it, because it is too slow to locate a specific data in list. The problem is that if I use one dimensional array to malloc()
memory space to the array, there is no enough continuous memory space on the laptop. Therefore, I plan to use two dimensional array to store it. So I have to get the num of lines in the file and then decide the size of each dimensional in this array via log
.
Thanks for all answers. This project is about reading two files. The first file is much larger than the second file. The second file is like:
1 13 0
2 414 1
3 10 0
4 223 1
5 2 0
The third num in each line is called "ID". For example, num "1" has ID 0, num "2" has ID 1, num "3" has ID "0". (Ignore the middle num in each line) And the first file is like:
1 1217907
1 1217908
1 1517737
1 2
2 3
2 4
3 5
3 6
If each num in the first file has the ID "0", I should store the both of num in each line into an data structure array. For example, we can see that num "1" has ID "0" in second file, so I need to store:
1 1217907
1 1217908
1 1517737
1 2
from my first file into the data structure array. The num "2" has ID"1" but num "3" has ID "0" and num "4" has ID "1", so need to store : 2 3
but not store 2 4
from my first file. That's why I need use array to store the two files. If I use two arrays to store them, I can check whether this num's ID is "0" fast in the array belongs to second file because using array is fast to locate a specific data, the index can be the value of the num directly.