strange behaviour when using fprintf within an if comparison
hi there, i have the following code :
PHP Code:
thanks, wernher |
try
printf ("\n %f is unequal\n",voltage); in if loop I think its null != null condition, which is always true. |
hoi,
thanks for the reply. I however know for certain that the if statement is entered because the "is unequal" statement is printed to the screen when previous_voltage and voltage are unequal. |
but what is prints ?
is there any value in voltage variable ? Can you share a sample value in voltage variable ? |
I do not see the problem of the fprintf statement but I do see other problems
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
|
hey,
ya, heres a sample of what it prints to the screen. Where "is unequal" is printed, it ought to write to the file (like it does when there is no if statement). Code:
-------------------------------------------------------------------------------------------------------- |
hey
are you closing program with control-c ? if yes use signal handler to close file pointer i.e. fclose(fp) ; this simple code all make empty file if you close it with ctrl-c main() { FILE *fp ; fp=fopen("abcd.test","w"); fprintf(fp,"test"); usleep(50000); //pause system //fclose(fp); } |
Quote:
|
try "return(0);" in if block after fprintf statement.
if it write anything, then you got the problem . (need to find solution) else need to find actual problem :( |
Quote:
|
Quote:
thanks for the tips, gonna clean the code up. no, i'm not redirecting, i'm prtinting to the screen and the file, what i print on the screen has more information than what imn printing to the file. |
Quote:
|
Quote:
Quote:
Quote:
|
ok
then a simple solution use fflush(fp) ; after fprintf |
Quote:
|
All times are GMT -5. The time now is 11:27 PM. |