Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<string.h>
- #include<stdio.h>
- #include <stdlib.h> //contians atoi for string to int conversion
- void parse(char *input, int *x, int *y, int *z){
- // serial port sends data that looks like int, int, int
- char *p;
- p = strtok(input, ",");
- if(p){
- *x=atoi(p);
- }
- p = strtok(NULL, ",");
- if(p){
- *y=atoi(p);
- }
- p = strtok(NULL, ",");
- if(p){
- *z=atoi(p);
- }
- }
- int main(){
- char input[16] = "545,394,2";
- int x=0,y=0,z=0;
- parse(input, &x,&y,&z);
- printf("X: %d\n", x);
- printf("Y: %d\n", y);
- printf("Z: %d\n", z);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement