Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] MicroC Concatenate and conversion

Status
Not open for further replies.

yanal

Junior Member level 1
Joined
Sep 20, 2015
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
149
if I have a char array like : getRequest[18] ,, How i can specify some digits of this array to a variable like : ID_1st;

Example : getReqest[1]=1; getRequest[3]=5 ;
:fight:
i want to store this two digits to variable that show the ID_1st is :15;

what is the type of ID_1st and how to Concatenate digits within it !!


I wish you have a nice day friends :)
 

Be sure not to confuse digit values like 1 with character codes like '1'.

Presumed you have two digit values and want to combine it to a single binary number, you simply multiply the first digit with 10
Code:
ID_1st  = 10* getReqest[1] +  getReqest[3];

Strings representing a digital number can be decoded with atoi() or sscanf().
 
  • Like
Reactions: yanal

    yanal

    Points: 2
    Helpful Answer Positive Rating
Strings representing a digital number can be decoded with atoi() or sscanf().

so if i have : getRequest[7]='1' ; and getRequest[8]='3' ;
i should define int variable like int x and use atoi() function ~~

int x;
char c;
char c2;

c=getRequest[7];
c2=getRequest[8];
x=10*atoi(c)+atoi(c2) ;

thats Correct or not ??
 

Be sure not to confuse digit values like 1 with character codes like '1'.

Presumed you have two digit values and want to combine it to a single binary number, you simply multiply the first digit with 10
Code:
ID_1st  = 10* getReqest[1] +  getReqest[3];

Strings representing a digital number can be decoded with atoi() or sscanf().


oops yes you are right i have character codes .. gerRequest[7]='1' ; getRequest[8]='5'

so how i can convert them to int or how i can put them to variable like long x = 15 ???
 

Try
Code:
atoi() or atol()
after terminating the arry with null character.
 
  • Like
Reactions: yanal

    yanal

    Points: 2
    Helpful Answer Positive Rating
could you please give me an example !!
if i have char getRequest[20];
and getRequest[7]='1';
and getRequest[8]='2';

how can i store this two as not character at Long variable as L_nm ; to be L_nm=12;
 
Last edited:

mikroC and mikroBasic PRO have atoi() and atol() functions. Search in Help File's Index. You will get example on how to use. Terminate the array with null character and use Ltrim() and Rtrim() and then atoi().

Example

Code:
unsigned int myInt = 0;

void main() {

     while(1) {
             getRequest[9] = '\0';
             Ltrim(getRequest);
             Rtrim(getRequest();
             myInt = atoi(getRequest); 
     }
}
 
  • Like
Reactions: yanal

    yanal

    Points: 2
    Helpful Answer Positive Rating
If it's no problem to modify the input string

Code:
get_request[9]=0;
L_nm = atoi(&get_request[7]);
otherwise

Code:
char temp[3];
strncpy(temp, &get_request[7], 2);
L_nm = atoi(temp);

- - - Updated - - -

Ltrim() and Rtrim() are no standard C functions.(And not required for the present problem anyway).
 
  • Like
Reactions: yanal

    yanal

    Points: 2
    Helpful Answer Positive Rating
I did it by this way :D you are so helpful .. regards :D

Code:
void x_array(){
int i;
 char x[1];
 x[0]=getRequest[7];
 x[1]='\0';
 i=atoi(x);
 portb=i;
 }
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top