C program to convert string to Integer

C program to convert string to Integer:
If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().

#include<stdio.h>
#include<stdlib.h>

main()
{
   int no;
   char num[3];

   printf("Please Enter Number : ");
   scanf("%s",num);

   //Convert String to Integer
   no=atoi(num);
   printf("\nString To Integer : %d",no);
}

OUTPUT:

Please Enter Number : 45

String To Integer : 45

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.