在turbo c ++中将字符串的一部分转换为整数

用户8522622

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

xmcp

我认为你需要的是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;
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章