Converting a part of string to an integer in turbo c++

570 views Asked by At

I want to find a way to convert the number in the string to an integer. i am able to find numbers in the string using isnum function but the problem is how to i make it an integer.

1

There are 1 answers

0
xmcp On BEST ANSWER

I think what you need is the atoi function.

Here is the code example from cplusplus.com:

/* atoi example */
#include <stdio.h>      /* printf, fgets */
#include <stdlib.h>     /* atoi */

int main ()
{
  int i;
  char buffer[256];
  printf ("Enter a number: ");
  fgets (buffer, 256, stdin);
  i = atoi (buffer);
  printf ("The value entered is %d. Its double is %d.\n",i,i*2);
  return 0;
}