|
|
View previous topic :: View next topic |
Author |
Message |
daalex
Joined: 10 Jan 2014 Posts: 10
|
splitting strings? |
Posted: Wed Feb 19, 2014 6:29 am |
|
|
Hello,
i'm working on a projekt and i have a little problem, maybe someone can give me a hint...
i send a string to my pic -> FF#255#255#1 and now i have to store these values between the # into variables
so i splitted the string with strtok, this works fine, but how can i store the splitted values to strings?
for example:
direction =FF
speedX =255
speedY =255
light =1
here is the part with the strtok:
Code: |
// split the string -> FF 200 255 1
char delimiter[] = "#";
char *ptr;
// first part
ptr = strtok(eingabe, delimiter);
while(ptr != NULL) {
printf(usb_putc, "found: %s\r\n", ptr);
// next parts
ptr = strtok(NULL, delimiter);
}
}
|
thanks in advance
alex |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9215 Location: Greensville,Ontario
|
|
Posted: Wed Feb 19, 2014 6:47 am |
|
|
hint: with your project open, press F11 to get the CCS C Help manual,locate strtok(),and see the example they show.It's very similar to what you want to do.
hth
jay |
|
|
daalex
Joined: 10 Jan 2014 Posts: 10
|
|
Posted: Wed Feb 19, 2014 7:11 am |
|
|
ok, this was a silly question, sorry :-)
i did it with strcpy and it works
Code: |
char delimiter[] = "#";
strcpy(direction, strtok(eingabe , delimiter));
strcpy(speedX, strtok(NULL , delimiter));
strcpy(speedY, strtok(NULL , delimiter));
strcpy(light, strtok(NULL , delimiter));
printf(usb_putc, "Direction: %s\r\n", direction);
printf(usb_putc, "speedX: %s\r\n", speedX);
printf(usb_putc, "speedY: %s\r\n", speedY);
printf(usb_putc, "Light: %s\r\n", light);
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|