• 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.

  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. int main() {
  5.    int number;
  6.    char number_string[3];
  7.  
  8.    printf("Please Enter a number : ");
  9.    scanf("%s", number_string);
  10.  
  11.    number = atoi(number_string);
  12.    printf("\n number_string : %d", number);
  13.  
  14.    getch();
  15. }


 Output:


convert String to int in c program

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu