first I'm looking for optimization, fast time execution
I would like to read data from input in C so here is my code (Linux)
int main(void) {
char command_str[MAX_COMMAND_SIZE];
while (!feof(stdin)) {
fgets(command_str, MAX_COMMAND_SIZE, stdin);
// Parse data
}
return EXIT_SUCCESS;
}
According to this post Read a line of input faster than fgets
? read()
function seems to be the solution.
The data input is like:
100 C
1884231 B
8978456 Z
...
From a file, so I execute my program like ./myapp < mytext.txt
It is not possible to know how many entries there is, it's could be 10, 10000 or even more.
Drop all the casts on malloc and realloc; they aren't necessary and clutter up the code
So if I use a dynamic array my app will be slower I think.
The idea is:
Read the whole input in one go into a buffer.
Process the lines from that buffer.
That's the fastest possible solution.
If someone would help me. Thanks in advance.