How to convert char to int in c language

w‮tual.ww‬turi.com
How to convert char to int in c language

Explicit conversion:

int i;
char c = 'A'; 
i = (int)c;

Conversion by ascii code calculation:

char c = '3';
int x = c - '0';
或者
int i = (int)(c - '0');

However, the above method can only convert a single char character.

How to convert string "123" to int?
You can use the following methods to convert using the atoi function:

## C# string to int
strcpy(str, "123");
val = atoi(str);
Created Time:2017-08-28 08:58:23  Author:lautturi