CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

splitting strings?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
daalex



Joined: 10 Jan 2014
Posts: 10

View user's profile Send private message

splitting strings?
PostPosted: Wed Feb 19, 2014 6:29 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Feb 19, 2014 6:47 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Feb 19, 2014 7:11 am     Reply with quote

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);
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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