Home C-tutorials C String to Int



C String to Int
Posted on: February 5, 2009 at 12:00 AM
In this section, you will learn how to convert a string represented value into an integer represented value in C.

C String to Int

     

In this section, you will learn how to convert a string represented value into an integer represented value in C. You can see in the given example that we have used the library function atoi() provided by the header file <stdlib.h>, to convert the string value of digits ("100") into int value. The number may consist of an optional sign and a string of digits, then only converted number is returned otherwise 0 is returned. This method can skip the initial whitespace characters like space, tab, new line etc. . 

Here is the code:

 

 

StringToInt.c

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int main() {
  int i;
  i = atoi("100");
  printf("The integer value is: %d", i);
  getch();
  return 0;
}

Output will be displayed as:

STRING~1.EXE

Download Source Code:

 

Related Tags for C String to Int:
cstringconvertiointegervalueintthistolearneareilsectioninnttreshowintosisllpreeaarstrreprrtvassriringthstaluprono


More Tutorials from this section

Ask Questions?    Discuss: C String to Int  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.