|
0 registered members (),
9,630
guests, and 4
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
diag_var with parameter 0
#277189
07/08/09 08:59
07/08/09 08:59
|
Joined: Feb 2006
Posts: 1,011 Germany
pegamode
OP
Serious User
|
OP
Serious User
Joined: Feb 2006
Posts: 1,011
Germany
|
Hi, I use a code quite similiar to this:
for(i=0; i<4;i++) {
diag_var("checking door: %3.0f", i);
}
The output is: checking door: %3.0f checking door: 1 checking door: 2 checking door: 3 As you can see the result isn't correct with value 0. I have the same problem in different codes. Regards, Pegamode.
|
|
|
Re: diag_var with parameter 0
[Re: jcl]
#277467
07/09/09 11:15
07/09/09 11:15
|
Joined: Feb 2006
Posts: 1,011 Germany
pegamode
OP
Serious User
|
OP
Serious User
Joined: Feb 2006
Posts: 1,011
Germany
|
I couldn't reproduce this behaviour by directly calling diag_var, too. But with this code the "error" occurs:
#include <default.c>
#include <acknex.h> // Pure Mode
void ediag(STRING* fctName, STRING* level, STRING* diagStr, var param) {
STRING* outputStr = str_create("");
if (fctName != NULL) {
str_cat(outputStr, "[");
str_cat(outputStr, fctName);
str_cat(outputStr, "]: ");
}
str_cat(outputStr, diagStr);
if (param == NULL) {
diag(outputStr);
} else {
diag_var(outputStr, param);
}
}
void main() {
diag("\n");
STRING* fctName = "void main()";
STRING* LEVEL_INFO = "INFO";
int i;
for(i=0; i < 5; i++) {
ediag(fctName, LEVEL_INFO, "test: %3.0f\n", i);
}
}
Can you identify an error in this code? Regards, Pegamode.
|
|
|
Re: diag_var with parameter 0
[Re: jcl]
#277555
07/09/09 15:43
07/09/09 15:43
|
Joined: Sep 2003
Posts: 9,859
FBL
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 9,859
|
if (param == NULL) {
diag(outputStr);
This code makes no sense. if you pass 0 as param, it will just output the string without using a parameter as NULL is defined to 0 by default. But even if you fix this, you'll always have your %3.0f in the string, as it is always appended, regardless whether you actually want to print a value or not.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|