Convert String To To Int C Code Example


Example 1: string to int c


atoi(str) is unsafe

This is the prefered method:
(int)strtol(str, (char **)NULL, 10)

Example 2: how to cast string to int in c


use atoi from the stdlib.h 
char *string = "hi";
int x = atoi(string);

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable