Say this is the file I want to read :
07983988 REMOVE String1
13333337 ADD String4 100
34398111 TRANSFER String5 String6 100
Those are the only 3 valid types of formats.
I'm using the following block of code to check what is the format of the line parsed :
// Read from file.
while (!feof(fd)) {
// Check for format.
if (fscanf(fd, "%d %s %s %s %lf", ×tamp, transaction_type_str, company1, company2, &value)) {
node_t *transaction = create_node((long int)timestamp, 1, company1, company2, value);
add_node(transactions, transaction);
} else if (fscanf(fd, "%d %s %s", ×tamp, transaction_type_str, company1)) {
node_t *transaction = create_node((long int)timestamp, 1, company1, NULL, 0);
add_node(transactions, transaction);
} else if (fscanf(fd, "%d %s %s %lf", ×tamp, transaction_type_str, company1, &value)) {
node_t *transaction = create_node((long int)timestamp, 1, company1, NULL, value);
add_node(transactions, transaction);
}
This however is giving me an infinite loop. I'm new to file I/O in C, and I'm wondering if its better to use a tokenized approach or line based format search approach.