Pages: [1]   Go Down
Author Topic: An array of char to a char  (Read 596 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 41
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I have an array of char (char cmd[]="1234"smiley-wink and i want to convert it to a char (char cmd1="1234"smiley-wink

I need to compare the char. If i'm using an array i need to use a for but i want to use something like:

if(cmd1 == "1234"){
    ....
    ....
}
Logged

London
Offline Offline
Faraday Member
**
Karma: 9
Posts: 6247
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

see the strcmp function: http://www.cplusplus.com/reference/clibrary/cstring/strcmp/
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 41
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

1) Can i use that function on Arduino?

2) Can i compare an array of char (char cmd[5]="1234") with a char (cmd1="1234") ?
Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 12
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
1) Can i use that function on Arduino?

2) Can i compare an array of char (char cmd[5]="1234") with a char (cmd1="1234") ?

Yes and yes smiley
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 41
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks smiley

That fubction have better performance then a FOR cycle?
Logged

London
Offline Offline
Faraday Member
**
Karma: 9
Posts: 6247
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I expect you would not notice any difference in performance between calling strcmp and doing an explicit compare in a for loop
« Last Edit: July 04, 2009, 12:28:33 pm by mem » Logged

Pages: [1]   Go Up
Jump to: