C Program to Convert String to Integer
String Program : Program to Convert String to Integer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#include<stdio.h> #include<stdlib.h> int main() { int num; char marks[3]; printf("Please Enter Marks : "); scanf("%s", marks); num = atoi(marks); printf("\nMarks : %d", num); return (0); } |
Output :
1 2 |
Please Enter Marks : 76 Marks : 76 |
Explanation :
- FOR More Details : [ Atoi Function ]
- Entered Number is in the form of “String“.
- Suppose Entered Number is 78 then Entered Number has Representation –
1 |
"76" |
- This “76” is unable to Perform Arithmetic Operation , so Our aim is To Convert String into Integer which can perform “Arithmetic Operations” Like Integer.
1 |
Convert "76" to 76 |