About Me

My photo
Raipur, Chhattisgarh, India
Hi , I am Amit Thakur. I have worked as a QA Engineer for two years and as a Java Developer for one year in NIHILENT TECHNOLOGIES PVT. LTD., Pune.Currently I am working as DEAN (Research & Development) in Bhilai Institute of Technology, Raipur.

Tuesday, September 3, 2013

C Program to Convert String to Integer

#include<stdio.h>
#include<stdlib.h>
void main()
{
int num;

// Variable marks is of Char Type
char marks[3] = "98";

printf("Please Enter Marks : ");
scanf("%s",marks);

num = atoi(marks);

printf("\nMarks : %d",num);
}

Output :
Please Enter Marks : 76
Marks : 76
Explanation :
  1. FOR  More Details : [ Atoi Function ]
  2. Entered Number is in the form of “String“.
  3. Suppose Entered Number is 78 then Entered Number has Representation -
"76"
  1. This “76″ is unable to  Perform Arithmetic Operation , so Our aim is To Convert String into Integer which can perform “Arithmetic Operations” Like Integer.
Convert "76" to 76

No comments: