Currently the code is reading the file and sort the records, as shown below,
#include"fileIO/file.h"
#define MAX_RECORD_SIZE 256 // Bad style
typedef struct{
int age;
char *lastName;
char *firstName;
}Person;
.....
int main(int argc, char *argv[]){
FILE *pFile = fopen("file.txt", "r");
....
callInsertionSort(getItemList(cache), getSize(getItemList(cache)), less);
}
where, file.txt
is,
Age,LastName,FirstName
50,B,A
30,A,B
20,X,D
10,F,A
10,A,B
90,V,E
60,N,M
Execution:
$./sort.exe Before sorting Age,LastName,FirstName 50 B A 30 A B 20 X D 10 F A 10 A B 90 V E 60 N M After sorting Age,LastName,FirstName 10 F A 10 A B 20 X D 30 A B 50 B A 60 N M 90 V E
Question:
Without using fopen()
, is there a way to get the shell to pass the contents of file.txt
as command-line arguments, one argument per line in the file, (through argv
by passing shell command (sort.exe
) parameters)?