-
fscanf issue
1)
Code:
// read salesman name field from text file
fscanf(salesmanPtr,"%s\t\t",buffer);
// write salesman name field to text file
fprintf(tempSalesmanPtr,"%s",buffer);
2)
Code:
// skip salesman name field from text file
fscanf(salesmanPtr,"%*s\t\t",buffer);
// write salesman name field to text file
fprintf(tempSalesmanPtr,"Name");
which one consumes more processing power and/or memory?
-
> which one consumes more processing power and/or memory?
1. It depends on your compiler, OS and library implementation.
2. The difference is almost certainly tiny compared to everything else going on.
-
Version one takes about 0.0000001 second on my machine, and version two takes about 0.0000001, give or take.
To answer the question meaningfully, you should have a test case with a large amount of data that is measurable. For example, make a "salesman" file that is at least 100MB in size, and then you can more easily measure any difference. Use a program like Windows Task Manager or top(1) to measure the memory usage.
-
The two code snippets do two different things--one reads a string into a buffer, and the other reads a string but discards it. Perhaps you should be concerned with using code that does what you need it to do, instead of using code that possibly runs faster but doesn't do what you need it to do.