c - How to combine two or three characters to one integer/character -
i getting characters uart example "\n43\n" or "\n912\n". intend make integer in order compare values in application.
example:
int = 43; int b; /*combine character getting uart copy integer "b";*/ if(a==b) { /*perform operation*/ }
#include<string.h> #include<stdio.h> int main() { int number; char a[30] = "\n43\n"; number = atoi(a); printf("magic %d",number); if(number == 43) printf("this works....!\n"); return 0; }
have heard ever atoi()
edit:
int main() { int number = 0; char a[30]; a[0] = '4'; a[1] = '3'; a[2] = '\0'; number = atoi(a); printf("magic %d",number); return 0; }
Comments
Post a Comment