atoi function usage

atoi (represented ascii to integer) is a function to convert the string to an integer number, and office application programs in the computer software.
int atoi (const char * nptr) function string nptr scan parameters, skips preceding whitespace (e.g., space, tab indentation) and the like.
If nptr nptr or can not be converted int an empty string, then 0 is returned. Specifically, this function requires that the string is converted to a decimal number appreciated. atoi string corresponding to the digital input of limitation in the size (the size of the int type), if it is too large may be given -1.
E.g:

//vs2013里调用printf函数请使用预处理命令#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
 
int main(void)
{
    int n;
    char *str = "12345.67";
    n = atoi(str);
    printf("n=%d\n",n);
    return 0;
}

Output:
n-= 12345

Published 29 original articles · won praise 13 · views 2736

Guess you like

Origin blog.csdn.net/zmx2473162621/article/details/103937585