When incrementing the float variable cf using one of the two statements
cf=cf+5;
or
cf=cf+inc;
where inc is a float variable that was set equal to 5
the value of cf is increased, but it is increased by a value other than 5
When incrementing the float variable cf using one of the two statements
cf=cf+5;
or
cf=cf+inc;
where inc is a float variable that was set equal to 5
the value of cf is increased, but it is increased by a value other than 5
I've never heard or seen of this but try adding a decimal point to the end and/or 'f'
Code:float var = 5.0f;
Asking the right question is sometimes more important than knowing the answer.
Please read the FAQ
C Reference Card (A MUST!)
Pointers and Memory
The Essentials
CString lib
Ok, here is some of the code:
int y;
float cf, inc, data;
char temp, ccf; //used as array
....
cf=300;
inc=5;
for (y=0; y<=3; y++)
{
printf("%f", cf); //to test the code
sprintf(ccf, "CF %fMZ", cf);
ibwrt(sa, ccf, 20L); //writes assembly to a GPIB bus
//sa is the bus address
sleep(1);
ibwrt(sa, "E1", 2L);
ibwrt(sa, "MA", 2L);
ibrd(sa, temp, 8L);
sscanf(temp, "%f", &data);
fprintf(dataout, "%f\n", data); //dataout defined elsewhere
cf = cf + inc;
}
when running this segment of code, the printf statement at the beginning of the loop will print:
300
11,234,345 or similiar
additional bizarre number
additional bizarre number
I hope that helps.
Thanks.
i'm not really sure what's going on here.
But just to point out something (don't know if it'll have an effect or not...)
you initialized ccf as char
but using sprintf() you treated it like a string...
try
or if thats not enoughCode:char ccf[8];
-LCCode:char ccf[16];
Asking the right question is sometimes more important than knowing the answer.
Please read the FAQ
C Reference Card (A MUST!)
Pointers and Memory
The Essentials
CString lib
Why floats? cf and inc are not floats in this case, they are integers. Even though most smart compilers will convert them to floats 300.0f and 5.0f, you should do this yourself.Code:float cf, inc, data; char temp, ccf; //used as array .... cf=300; inc=5;
I don't understand why you are using - make that misusing -floats.
Again and again I've looked at this code and it looks like some attempt to write a crude compiler for something. Are you trying to place assembly opcodes directly into memory or something?? I'm totally lost.
Here's a hint: cf stands for center frequency. Want to take a guess what sa stands for?Originally posted by Bubba
Why floats? cf and inc are not floats in this case, they are integers. Even though most smart compilers will convert them to floats 300.0f and 5.0f, you should do this yourself.
I don't understand why you are using - make that misusing -floats.
Again and again I've looked at this code and it looks like some attempt to write a crude compiler for something. Are you trying to place assembly opcodes directly into memory or something?? I'm totally lost.