6/21/2018 - 12:30 AM

Convert String to Integer in C

Convert String to Integer in C

atoi - convert a string to an integer

atoi returns the string successfully converted to an integer. For example, the string "5" would simply return the int 5. If no valid conversion could be performed, it returns zero.


int converted = atoi("5");
printf("%d\n", converted);

* Remember to always include the library that it's in:

#include <stdlib.h>
int atoi(string str);