Convert char to int


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

#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:
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.