Hello
Can anybody explain to me why the following four FPRINTF lines of code
yield different results to their Console counterparts on the next line?
By my reckoning the results should be te same but one set are printed
to the console window and the other to a text file. The Console lines
are definitely creating correct results because they are a product of
help code for Microsoft Visual Studio .NET and the results look good.
The fprintf lines of code (my code) are definitely producing incorrect
results and all four of the outputs are often identical. Am I doing
some memory management incorrectly???
#include "stdafx.h"
#using <mscorlib.dll>
#include <tchar.h>
#include <windows.h>
#include <stdio.h>
using namespace System;
// This is the entry point for this application
int _tmain(void)
{
_int64 ctr1 = 0, ctr2 = 0, freq = 0;
int acc = 0, i = 0;
FILE *storage;
//Start timing the code
if(QueryPerformanceCounter((LARGE_INTEGER *)&ctr1) != 0)
{
storage = fopen("C:\\TestTimer.txt", "a"); //Open a file for data
output
//Code segment is being timed
for(i=0; i<100; i++) acc++;
//Finish timing the code
QueryPerformanceCounter((LARGE_INTEGER *)&ctr2);
fprintf(storage, "Start Value %i\n", ctr1.ToString());
Console::WriteLine("Start Value: {0}",ctr1.ToString());
fprintf(storage, "End Value %i\n", ctr2.ToString());
Console::WriteLine("End Value: {0}",ctr2.ToString());
QueryPerformanceFrequency((LARGE_INTEGER *)&freq);
fprintf(storage, "Frequency %i\n", freq.ToString());
Console::WriteLine(S"QueryPerformanceCounter minimum resolution:
1/{0} seconds.",freq.ToString());
fprintf(storage, "Time %i\n", ((ctr2-ctr1) * 1.0 /
freq).ToString());
Console::WriteLine("100 Increment time: {0} seconds.",((ctr2-ctr1) *
1.0 / freq).ToString());
fclose(storage);
}
return 0;
} 4 2913
wallacej wrote: Can anybody explain to me why the following four FPRINTF lines of code yield different results to their Console counterparts on the next line?
Probably because you're not using 'fprintf' correctly...
By my reckoning the results should be te same but one set are printed to the console window and the other to a text file. The Console lines are definitely creating correct results because they are a product of help code for Microsoft Visual Studio .NET and the results look good. The fprintf lines of code (my code) are definitely producing incorrect results and all four of the outputs are often identical. Am I doing some memory management incorrectly??? [...non-standard code removed mostly...] fprintf(storage, "Start Value %i\n", ctr1.ToString());
What does 'ToString()' return? A const char*? Why are you printing it
with %i? Doesn't %i require a value of type 'int' (or convertible to it)?
[...]
Please forward your further inquiries about Windows API to a newsgroup
dedicated to Windows programming, comp.os.ms-windows.programmer.win32 or
to a microsoft newsgroup for .NET stuff: microsoft.public.dotnet.languages
V
thanks for that, knew it might be a stupid mistake.
One more thing, do you know why the fprintf line of code would work in
one project but not in another?
I transfered the code to a cpp file in an existing project and i get an
error messagge
'left of 'To String' must have class/struct/union type'
Could this be because the original project is managed c++? and if so
how would i get around this?
wallacej wrote: thanks for that, knew it might be a stupid mistake. One more thing, do you know why the fprintf line of code would work in one project but not in another?
I transfered the code to a cpp file in an existing project and i get an error messagge 'left of 'To String' must have class/struct/union type'
Could this be because the original project is managed c++? and if so how would i get around this?
Yes, it definitely could. Managed C++ (a different language, really)
is off-topic here, sorry. Ask in a newsgroup dedicated to Visual C++
to learn more about it: microsoft.public.vc.language (or any other
microsoft.public.* that is relevant).
Good luck!
V
On 23/2/05 3:50 AM, wallacej wrote: //Code segment is being timed for(i=0; i<100; i++) acc++;
Also, to state the obvious, this piece of code does nothing and
Microsoft C++ will optimize it away if you allow it to. So this code
takes 0 time to execute. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: rawCoder |
last post by:
Hi All,
I have a *.cer file, a public key of some one and I want to encrypt some
thing using this public key.
Can someone point me to a sample code for Encrypting some file using...
|
by: Mike |
last post by:
When trying to compile (using Visual Web Developer 2005 Express Beta;
frameworkv2.0.50215 ) the source code below I get errors (listed below due to
the use of ICallBackEventHandler. Ultimately I...
|
by: Christopher Benson-Manica |
last post by:
Why can't I use a class destructor in a using declaration:
using MyClass::~MyClass;
?
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org ...
|
by: beliavsky |
last post by:
Many of my C++ programs have the line
using namespace std;
but the "Accelerated C++" book of Koenig and Moo has many examples
where the library names are included one at a time, for example
...
|
by: Petter Reinholdtsen |
last post by:
I ran into a problem on HP-UX 11.00 the other day, where it refused to
compile a program using 'using namespace std;' at the top. The reason
seem to be that the compiler refuses to accept 'using...
|
by: john.burton.email |
last post by:
I've done some extensive searching and can't seem to find an answer to
this -
Is it correct to using "using" with templates, for example:
using std::vector;
Or do I need to specify the type...
|
by: Enos Meroka |
last post by:
Hallo,
I am a student doing my project in the university.. I have been trying
to compile the program using HP -UX aCC compiler, however I keep on
getting the following errors.
...
|
by: Calum Grant |
last post by:
In older C++ computer books, you'll often see
using namespace std;
even in my 1996 copy of Stroustrup. Nowadays, it seems to be considered
better to qualify names to make it clearer what...
|
by: JDeats |
last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting
and decrypting a file.
http://support.microsoft.com/kb/307010
In .NET 2.0 this approach is not fully supported (a .NET 2.0...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |