- We can convert string to integer in c Programming by using atoi() function.
- atoi() is a library function from C.
- int atoi(const char *str) ;
- Now we will write a C program to convert String format number to integer.
- Read input from user as string.
- Convert string to integer using atoi() function.
Program #1: Write a C program to convert String to integer in c Programming.
- #include<stdio.h>
- #include<stdlib.h>
- int main() {
- int number;
- char number_string[3];
- printf("Please Enter a number : ");
- scanf("%s", number_string);
- number = atoi(number_string);
- printf("\n number_string : %d", number);
- getch();
- }
Output:
No comments