I am trying to write a program which takes a string, saves the last 4 digit as a 16-radix number and convert it to 10-radix number.
In sum, I will just use it to measure distance by Blutooth module, works theorically :/
I successfully get last digits of a defined string, and I don't think I will have a problem about make this work on the microcontroller
Code:
#include <stdio.h>
int main()
{
char c[13]="kttt0FDH";
int i;
int m=0;
printf("---\n");
while(c[i]!=0)
{
printf("%c", c[i]);
i++;
m++;
}
//printf("\n%d", m);
// printf("\n%d", i);
int y=m-4;
int f;
char k[4];
i=0;
for(f=y;f<=y+3;f++)
{
k[i]=c[f];
i++;
}
printf("\n\n%s", k);
return 0;
}
But when I add the rest of the code, the computer stops it.
Code:
#include <stdio.h>#include <math.h>
int main()
{
double RSSI;
char c[13]="kttt0FDF";
int i;
int m=0;
printf("---\n");
while(c[i]!=0)
{
printf("%c", c[i]);
i++;
m++;
}
//printf("\n%d", m);
// printf("\n%d", i);
int y=m-4;
int f;
char k[4];
i=0;
for(f=y;f<=y+3;f++)
{
k[i]=c[f];
i++;
}
// printf("\n\n%s", k);
for(i=0;i<=3;i++)
{
if(k[i]=='0')
RSSI=RSSI+0*pow(16,3-i);
if(k[i]=='1')
RSSI=RSSI+1*pow(16,3-i);
if(k[i]=='2')
RSSI=RSSI+2*pow(16,3-i);
if(k[i]=='3')
RSSI=RSSI+3*pow(16,3-i);
if(k[i]=='4')
RSSI=RSSI+4*pow(16,3-i);
if(k[i]=='5')
RSSI=RSSI+5*pow(16,3-i);
if(k[i]=='6')
RSSI=RSSI+6*pow(16,3-i);
if(k[i]=='7')
RSSI=RSSI+7*pow(16,3-i);
if(k[i]=='8')
RSSI=RSSI+8*pow(16,3-i);
if(k[i]=='9')
RSSI=RSSI+9*pow(16,3-i);
if(k[i]=='A')
RSSI=RSSI+10*pow(16,3-i);
if(k[i]=='B')
RSSI=RSSI+11*pow(16,3-i);
if(k[i]=='C')
RSSI=RSSI+12*pow(16,3-i);
if(k[i]=='D')
RSSI=RSSI+13*pow(16,3-i);
if(k[i]=='E')
RSSI=RSSI+14*pow(16,3-i);
if(k[i]=='F')
RSSI=RSSI+15*pow(16,3-i);
}
return 0;
}
It results in:
Adsız - Hızlı Resim
The language is Turkish. It says as:"İsimsiz10.exe stopped working. A problem stopped the programs proper working.Windows will close it and tell if there is a solution." It says nothing then..
I used switch-case, it did not work either.
Code:
for(i=0;i<=3;i++) {
switch(k[i]) {
case '0' :
RSSI=RSSI+0*pow(16,3-i);
break;
case '1' :
RSSI=RSSI+1*pow(16,3-i);
break;
case '2' :
RSSI=RSSI+2*pow(16,3-i);
break;
case '3' :
RSSI=RSSI+3*pow(16,3-i);
break;
case '4' :
RSSI=RSSI+4*pow(16,3-i);
break;
case '5' :
RSSI=RSSI+5*pow(16,3-i);
break;
case '6' :
RSSI=RSSI+6*pow(16,3-i);
break;
case '7' :
RSSI=RSSI+7*pow(16,3-i);
break;
case '8' :
RSSI=RSSI+8*pow(16,3-i);
break;
case '9' :
RSSI=RSSI+9*pow(16,3-i);
break;
case 'A' :
RSSI=RSSI+10*pow(16,3-i);
break;
case 'B' :
RSSI=RSSI+11*pow(16,3-i);
break;
case 'C' :
RSSI=RSSI+12*pow(16,3-i);
break;
case 'D' :
RSSI=RSSI+13*pow(16,3-i);
break;
case 'E' :
RSSI=RSSI+14*pow(16,3-i);
break;
case 'F' :
RSSI=RSSI+15*pow(16,3-i);
break;
}
}
printf("\n\n%f", RSSI);
My best guess is it is about the code after I seperated the last digits, but I could not solve it by myself after some trials and search.
This works by itself:
Code:
#include <stdio.h>#include <math.h>
int main()
{
char k[3];
scanf("%s", &k);
printf("%s\n", k);
double RSSI;
int i;
for (i=0;i<=2;i++)
{
if(k[i]=='0')
RSSI=RSSI+5*pow(16,3-i);
}
printf("%f", RSSI);
return 0;
}
Thanks...