C Program to Convert String to Integer !!

August 24, 2024 No Comments » Hits : 500





String Program : 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\0"
  1. This “76\0″ is unable to Perform Arithmetic Operation , so Our aim is To Convert String into Integer which can perform “Arithmetic Operations” Like Integer.
Convert "76\0" to 76

Incoming search terms: