c convert to int code example
Example 1: type change in c
#include <stdio.h>
main() {
int sum = 17, count = 5;
double mean;
mean = (double) sum / count;
printf("Value of mean : %f\n", mean );
}
Example 2: string to int c
atoi(str) is unsafe
This is the prefered method:
(int)strtol(str, (char **)NULL, 10)
Example 3: how to cast string to int in c
use atoi from the stdlib.h
char *string = "hi";
int x = atoi(string);