Looks correct to me. I'll take a closer look.This is driving me nuts! How do you print a % sign using (s)printf? I'm using Visual Studio 2003 .NET and the following code just prints the number and misses the '%' off the end.
if (hash_probes){
d = (double)hash_hits;
d = (100 * d / hash_probes );
sprintf(s, "info string Hash Probe Effectiveness: %5.1f%%\n", d);
send_command(s);
}
Thanks!
Steve
Something's strange:This is driving me nuts! How do you print a % sign using (s)printf? I'm using Visual Studio 2003 .NET and the following code just prints the number and misses the '%' off the end.
if (hash_probes){
d = (double)hash_hits;
d = (100 * d / hash_probes );
sprintf(s, "info string Hash Probe Effectiveness: %5.1f%%\n", d);
send_command(s);
}
Thanks!
Steve
I have almost exactly the same source here, and it works (GCC, ICC, MSVC). %% is correct.if (hash_probes){
d = (double)hash_hits;
d = (100 * d / hash_probes );
sprintf(s, "info string Hash Probe Effectiveness: %5.1f%%\n", d);
send_command(s);
}
Perhaps I should elaborate. printf(s) will not work (in general) when s contains a "%", however printf("%s", s) will work.Are you using s in a further [s]printf call? Then expect problems, becuase now it will be a single "%" and this will not be valid.
Thanks for your help with this. It puzzles me.can you please show your definitions for s and d?
This will be a problem, see my other post.and for completeness...
void send_command(char *t)
{
static size_t i;
i = strlen(t);
if (i>0){
printf(t);
This solves it!! Thanks a million!This will be a problem, see my other post.
Better use
printf("%s", t);
BTW. These seem to be a lot of lines of code - too many IMHO. Also they include some unneeded casts (but one probably can discuss endlessly about this, I won't, I just wanted to mention it once). My suggestions would be:void uci_show_stats()
{
static char s[1024];
double d;
if (uci_show_strings){
if (hash_probes){
d = (double)hash_hits;
d = (100 * d / hash_probes );
sprintf(s, "info string Hash Probe Effectiveness: %5.1f%%\n", d);
send_command(s);
}
if (cutoffs){
d = (double)primary_cutoffs;
d = (100 * d / cutoffs );
sprintf(s, "info string Move Order Effectiveness: %5.1f%%\n", d);
send_command(s);
}
}
}
and for completeness...
void send_command(char *t)
{
static size_t i;
i = strlen(t);
if (i>0){
printf(t);
if (t[i-1]!='\n') printf("\n");
fflush(stdout);
}
}
>void uci_show_stats()BTW. These seem to be a lot of lines of code - too many IMHO. Also they include some unneeded casts (but one probably can discuss endlessly about this, I won't, I just wanted to mention it once). My suggestions would be:void uci_show_stats()
{
static char s[1024];
double d;
if (uci_show_strings){
if (hash_probes){
d = (double)hash_hits;
d = (100 * d / hash_probes );
sprintf(s, "info string Hash Probe Effectiveness: %5.1f%%\n", d);
send_command(s);
}
if (cutoffs){
d = (double)primary_cutoffs;
d = (100 * d / cutoffs );
sprintf(s, "info string Move Order Effectiveness: %5.1f%%\n", d);
send_command(s);
}
}
}
and for completeness...
void send_command(char *t)
{
static size_t i;
i = strlen(t);
if (i>0){
printf(t);
if (t[i-1]!='\n') printf("\n");
fflush(stdout);
}
}
To me, this looks slightly easier to follow and a bit more dense (less lines of codes, no unneeded casts). There is one main difference. This send_command function will possibly change t[]. Your one did not (however you did not indicate, that you care about it - for example by saying void send_command(const char *t)). I did not test it ...
By using puts, the problem with a "%" inside the first argument to printf is avoided from the start.
Cheers,
Dieter
My suggestion: http://cm.bell-labs.com/cm/cs/cbook/. I bought the first edition many years ago (it was stolen from my desk ... perhaps a small indication of the quality of this book). One of the best technical books I ever read. It is very compact, but still explains everything really needed. Almost free of errors (when I go to the local book shop and look through any random book about C or C++, I typically can detect many errors on the first view, not so, with this book). One of the authors (Dennis Ritchie) is the main "architect" of the C language (together with Ken Thompson, who is also very well known in the computer chess history).Can you, or others, recommend any good books intermediate 'C' book?
I must agree with Dieter.My suggestion: http://cm.bell-labs.com/cm/cs/cbook/. I bought the first edition many years ago (it was stolen from my desk ... perhaps a small indication of the quality of this book). One of the best technical books I ever read. It is very compact, but still explains everything really needed. Almost free of errors (when I go to the local book shop and look through any random book about C or C++, I typically can detect many errors on the first view, not so, with this book). One of the authors (Dennis Ritchie) is the main "architect" of the C language (together with Ken Thompson, who is also very well known in the computer chess history).Can you, or others, recommend any good books intermediate 'C' book?
How could I forget, to mention http://users.powernet.co.uk/eton/unleashed/. I did not read this book (I never saw it in one of the local book stores I typically visit - if it were there, I certainly would buy it). You might see a very well known name (to the readers of the WB-Forum) in the list of the authors! I "know" other names of the author list, too (from news postings and/or mail). I think they all will know very well, about what they write (I would not say this about many other books about C, that I saw).Can you, or others, recommend any good books intermediate 'C' book?
For the Dennis Ritchie book, used paperbook copies start here from about $15 , new paperback go for about $32, used hardcover editions start @ $67I must agree with Dieter.My suggestion: http://cm.bell-labs.com/cm/cs/cbook/. I bought the first edition many years ago (it was stolen from my desk ... perhaps a small indication of the quality of this book). One of the best technical books I ever read. It is very compact, but still explains everything really needed. Almost free of errors (when I go to the local book shop and look through any random book about C or C++, I typically can detect many errors on the first view, not so, with this book). One of the authors (Dennis Ritchie) is the main "architect" of the C language (together with Ken Thompson, who is also very well known in the computer chess history).Can you, or others, recommend any good books intermediate 'C' book?
Another thing worth learning is to download the C FAQ:
http://www.faqs.org/faqs/C-faq/faq/
Even experienced programmers may learn something new.
Return to Archive (Old Parsimony Forum)
Users browsing this forum: No registered users and 26 guests