- Home Page of ProjectGuideline.com ›
- Forums ›
- Get Help to do your B.E., and M.E., M.Tech., & M.S., Project in Ns2 ›
- Strange problem with ns2 printf
not sure if is ns2 problem or c++ issue,
i did a function call testingprint(); somewhere else
int ff2 = 0;
void
Myprog::testingprint()
{
if(ff2 == 0){
#ifdef DEBUG
fprintf(stderr, “I am from %d node TESTING n”, index);
#endif
printf(“AT(%d) hello TESTING n”, index);
testingprint2();
ff2 = 1;
}
}
i notice that if my printf are within if else statements which are in a function(testingprint()), only node 0 will be printed
I am from 0 node TESTING
AT(0) hello TESTING
, but if i remove the if else statements, all my nodes will print.
I am from 0 node TESTING
AT(0) hello TESTING
I am from 1 node TESTING
AT(1) hello TESTING
I am from 2 node TESTING
AT(2) hello TESTING
im only having this problem when there is if else in a function, if the if else is not in a function but in the main, there is no prob 🙁 anyone knows whats wrong?
certainly it will not be a problem with ns2 or C++ . your logical error will be the cause of this error (logical error).
Actually, the question was not clear.
“i notice that if my printf are within if else statements which are in a function(testingprint()), only node 0 will be printed
but if i remove the if else statements, all my nodes will print.”
You are checking the value of ff2 in the if statement. so in the first case, ff2 seems to be having value 0 if and only if the index=0. So it is printing for node 0 only.
If you are removing the if, then all it will not consider the value ff2 and so may print everything.
[/i]
@CharlesPandian wrote:
certainly it will not be a problem with ns2 or C++ . your logical error will be the cause of this error (logical error).
Actually, the question was not clear.
“i notice that if my printf are within if else statements which are in a function(testingprint()), only node 0 will be printed
but if i remove the if else statements, all my nodes will print.”
You are checking the value of ff2 in the if statement. so in the first case, ff2 seems to be having value 0 if and only if the index=0. So it is printing for node 0 only.
If you are removing the if, then all it will not consider the value ff2 and so may print everything.
[/i]
thanks for yr reply, i realise its my coding problem 😳