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 support@ccsinfo.com

Get string into a string

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



Joined: 08 Mar 2017
Posts: 40

View user's profile Send private message

Get string into a string
PostPosted: Sun Mar 26, 2017 3:34 pm     Reply with quote

Suggestion of best way to get a specific string into a string.

ex: gets(x) // suppose received from serial "FA12345"

Wants to eliminate FA and atoi32 12345.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sun Mar 26, 2017 3:41 pm     Reply with quote

CCS 'C' comes with a whole load of standard string handling functions.
Have a look there, you should find what you want.

Mike
jpts



Joined: 08 Mar 2017
Posts: 40

View user's profile Send private message

PostPosted: Sun Mar 26, 2017 6:45 pm     Reply with quote

I did look string handling, and found different way to get same results...but Iwould like to hear about experts what is best...mean more effective.

memmove(x,x+2,5); worked ...but I´m not sure if is the right one
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 26, 2017 6:59 pm     Reply with quote

Post the final string that you would like to see. Do you want "12345" ?
Then you can use this function:

atoi32(char *ptr)

The atoi32() function takes a pointer to the string as its parameter.
Just point it to the 2nd char in the string. Example:
Code:

#include <18F46K22.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)

#include <stdlib.h>
#include <input.c>

//===========================
void main()
{
int8 input_array[20];
int32 result;

get_string(input_array, 10);   // Get 10 chars max

result = atoi32(input_array +2); 

printf("result = %lu \n\r", result);

while(TRUE);
}
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