0
I have variables of the type Unsigned Long Int
and would like to save its value in a string
, to perform calculation of checksum and send via serial communication.
void Payload(int long unsigned lastTime, float deltaOne, float deltaTwo, int factor){
[...]
sprintf(buffer, "CAPTION,%u,%s,%s,%d," lastTime,deltaOne,deltaTwo,factor);
SendWithCS(buffer);
}
But the converted value of int
for string
it’s not the same.
Example:
int long unsigned record = 11285600;
float delta1 = 50.2035;
float delta2 = 54.2035
int factor = 5;
Payload(record,delta1,delta2,factor);
Exit:
CAPTION,22601,50.2035,54.2035,5,3F
Why is the first a pointer? Will you send this value or pointer? How can 5 data get out if you are only using 4? This code does not even compile, it has many errors.
– Maniero
ops, I typed wrong rs
– Elliot Alderson
There are other errors, see all. Read the whole comment above.
– Maniero
This code is part of another much larger code, but as the other parts are not relevancy just put a fragment of it, the last output value is given by the Sendwithcs; 54.2035,5,
– Elliot Alderson
Why should you show 22601 if what you’re going through is 11285600?
– Maniero
That’s the question, why are you showing 22601 if I’m passing 11285600?
– Elliot Alderson
Your question is confused, because this seemed to be what you expected. Actually I used your code, there is a lot of error in it, and it does not generate that no, certainly the code you are running is different from this posted.
– Maniero
This code will not compile, it depends on other functions, it is only possible to explain the part of sprintf , the only doubt is why I enter the variable in the function and the buffer string is presented with a value that differs from the original format.
– Elliot Alderson
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site.
– Maniero