在turbo c ++

时间:2017-08-27 07:15:49

标签: c++ turbo-c++

我想找到一种方法将字符串中的数字转换为整数。 我能够使用 isnum 函数在字符串中查找数字,但问题是如何使其成为整数

1 个答案:

答案 0 :(得分:1)

我认为您需要的是atoi功能。

以下是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;
}
相关问题