atoi用法

mac2022-06-30  100

来自头文件 #include <stdlib.h>

atoi()函数用来将字符串转换成整数(int)

int atoi(const char* str) ;

从流中获取字符串:

char* fgets(char*str, int num, FILE*stream );

num: 最大字符个数,包括终止符号

stream:stdin

#include <stdio.h> #include <stdlib.h> int main() { int i; char buffer[256]; printf("Enter a number:"); fgets(buffer, 256, stdin); i = atoi(buffer); printf("The value entered is %d.", i); return 0; }

 

转载于:https://www.cnblogs.com/Shinered/p/9865979.html

最新回复(0)