View previous topic :: View next topic |
Author |
Message |
jpts
Joined: 08 Mar 2017 Posts: 40
|
Get string into a string |
Posted: Sun Mar 26, 2017 3:34 pm |
|
|
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
|
|
Posted: Sun Mar 26, 2017 3:41 pm |
|
|
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
|
|
Posted: Sun Mar 26, 2017 6:45 pm |
|
|
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
|
|
Posted: Sun Mar 26, 2017 6:59 pm |
|
|
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);
}
|
|
|
|
|