函数atoi 将字符串转化为int
int atoi (const char * str);
需要库 #include <stdlib.h>
例子:
/* 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;
}
本文介绍如何使用C语言中的atoi函数将输入的字符串转换成整数,并通过一个简单示例展示了atoi函数的基本用法及注意事项。





