hello guys, please help me...
i want to convert my code. but serial monitor not same with my value..
this is my code. thank you guys
int port = 418171;
String x= " ";
void setup(){
port = (x).toInt();
Serial.print(F("Data port :"));
Serial.println (String(port));
}
void loop(){}
but (x) value is -17365
J-M-L
September 5, 2022, 8:19am
2
ginasoniah:
port = (x).toInt();
What is x??
String portString = "418171"; // hum, Port numbers range from 0 to 65535…
void setup(){
long portNumber = portString.toInt();
Serial.print(F("Data port :"));
Serial.println (portNumber);
}
void loop(){}
(Typed from my iPhone, mind typos)
Remember that Port numbers range from 0 to 65535
1 Like
thank you solved !! I change variable port tobe long
my problem now how to convert string to char
char server = "122.122.11.11";
String x =" ";
void setup(){
server = x ;
Serial.print(F("server:"));
Serial.println (server);
}
void loop(){}
b707
September 5, 2022, 8:50am
4
Do you read what others write to you?
Look carefully at the example above - if you need to convert a String to a something - then the original value must be a String .
Why are you again setting the IP to the char, and the String is empty?
I think that it will better if you try to do it yourself this time.
my code definetely not like that its just sample simple code.
I am sorry my fault ...
char server = " ";
String x =" 122.12.12 ";
void setup(){
server = x ;
Serial.print(F("server:"));
Serial.println (server);
}
void loop(){}
my code like that
b707
September 5, 2022, 9:06am
6
ginasoniah:
String x =" 122.12.12 ";
What's the purpose of the empty spaces around the value?
Do you seen the documentation for String class in the Arduino reference? Take a look at c_str() method
The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords.
J-M-L
September 5, 2022, 11:30am
7
ginasoniah:
char server = " ";
That’s not good it needs to be
char server[20] = ""; // whatever size is appropriate
The char type is just for one character (one byte - so not even utf8 characters if you venture outside common ASCII)
system
Closed
March 4, 2023, 11:31am
8
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.