rref requestable via mqtt
This commit is contained in:
3
test/.gitignore
vendored
3
test/.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
airspeed
|
||||
heading
|
||||
mqtt
|
||||
mqtt.h
|
||||
mqtt.h
|
||||
strtoint
|
44
test/strtoint.c
Normal file
44
test/strtoint.c
Normal file
@ -0,0 +1,44 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int *strtoint(char *in, size_t start, size_t n)
|
||||
{
|
||||
int *ret = malloc(sizeof(int));
|
||||
*ret = 0;
|
||||
int offset = start + n - 1;
|
||||
|
||||
if (offset < 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
int position = offset - i;
|
||||
printf("foo: %c\n", in[position]);
|
||||
if (in[position] >= '0' && in[position] <= '9')
|
||||
{
|
||||
*ret += (in[position] - '0') * pow(10, i);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
char *in = "abcd123";
|
||||
int *ret = strtoint(in, 4, 3);
|
||||
if (ret != NULL)
|
||||
{
|
||||
printf("%s | %d\n", in, *ret);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("ret is NULL\n");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user