Pages: [1]   Go Down
Author Topic: Beginner question about char.  (Read 227 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi.. I would like to know how to get character at specific array position to the last.. and covert is as a string..


Example: Char char1[50] = "Legend";


I want a Result:    String string1 = "gend";
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3382
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi.. I would like to know how to get character at specific array position to the last.. and covert is as a string..

You mean String. A string is a null-terminated array of chars like your first line. A String is an object with a well documented amount of issues.

Given

Code:
char char1[] = "Legend";

you can access a latter part of it by taking the address of the first array element:

Code:
Serial.println(&char1[2]);

Would produce "gend"
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

wow thanks you... what if i only want "gen"?
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3382
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Replace the 'd' with a '\0' (null terminator).
Logged

Pages: [1]   Go Up
Jump to: