atoi用法

来自头文件 #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;

}
The Safest Way to Get what you Want is to Try and Deserve What you Want.
原文地址:https://www.cnblogs.com/Shinered/p/9865979.html