int in string c
#include <stdio.h>
#include <stdlib.h>
int main() {
char str[] = "123";
int num;
// Using atoi function to convert string to integer
num = atoi(str);
// Printing the result
printf("The integer value is: %d\n", num);
return 0;
}
Include necessary header files:
stdio.h
for input/output operations andstdlib.h
for theatoi
function.Declare a character array
str
and initialize it with the string "123".Declare an integer variable
num
to store the converted integer value.Use the
atoi
function to convert the stringstr
to an integer and assign the result to the variablenum
.Print the converted integer value using
printf
.