xxxxxxxxxx
atoi(str) is unsafe
This is the prefered method:
(int)strtol(str, (char **)NULL, 10)
xxxxxxxxxx
#include <stdio.h>
#include <stdlib.h>
int main()
{
char ch[]="123";
int a=atoi(ch);
printf("%d",a);
return 0;
}
xxxxxxxxxx
#include <stdio.h>
#include <stdlib.h>
int main() {
char str[] = "12345";
int num = atoi(str);
printf("Converted to integer: %d\n", num);
return 0;
}
xxxxxxxxxx
// C program to demonstrate
// the working of SSCANF() to
// convert a string into a number
#include <stdio.h>
int main()
{
const char* str = "12345";
int x;
sscanf(str, "%d", &x);
printf("\nThe value of x : %d", x);
return 0;
}