Convert char to int

Hello,

New to programming, I've tried various ways to convert a char to an int. I've googled for days. Please, can some help me.

When I convert to an int, I want the answer to be 1. however I get two separate converted values

channel and uni
1073644752
1073644748

#include <ESP8266WiFi.h> 

char test_1[4] = "1";
char test_2[4] = "1";

int channel;
int universe;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
channel = (int)test_1;
universe = (int)test_2;
Serial.println("channel and uni ");
Serial.println (channel);
Serial.println (universe);
}

void loop() {
  // put your main code here, to run repeatedly:

}

You need to convert string to number, like so:

channel = atoi(test_1);
universe = atoi(test_2);

I believe that atoi is short for "ascii to integer" :slight_smile:

atoi (ascii to int) probably won't work. Converting it to int won't work. The number in question is more than 65,535. I would suggest trying converting to long and using atol (ascii to long).

atoi will be fine - the number the OP is trying to convert to int is one. The problematic numbers appeared because of an attempt to cast an address to an int.