I have an input file that contains numerical input parameters mixed with otherwise irrelevant text.
E.g.
//file orig_data.txt
Number of customers
25
Customer_id Customer_SSN
1 1234
2 3456
....
25 0123
All input files have this same format although the number of customers may be different. The above example has 25 customers, another input file may have number of customers to be 35 and hence 35 rows worth of data (id and SSN)
One way for me would be to strip the text out manually and create a modified input data that just has the numerical data.
//file modified_data.txt
25
1 1234
2 3456
....
25 0123
With this type of input file (modified_data.txt
), I can have the following code to read the data in.
void readdata() {
FILE* fp = fopen("modified_data.txt","r");
fscanf(fp, "%d", &no_cust);
int* ids = new int[no_cust+1];
int* ssns = new int [no_cust+1];
for(int i = 1; i <= no_cust; i++)
fscanf(fp, "%d %d", &ids[i], &ssns[i]);
//other stuff
}
Is there a way to suitably work with orig_data.txt
itself and have the function that reads this file skip over the first and third lines that contain the unneeded text?