古詩詞大全網 - 成語查詢 - c語言中atof 和atoi是什麽意思?

c語言中atof 和atoi是什麽意思?

這兩個都是C語言的庫函數

函數名: atoi?

功 能: 把字符串轉換成長整型數?

用 法: #include <stdlib.h>?

int atoi(const char *nptr);?

程序例:?

#include <stdlib.h>?

#include <stdio.h>?

int main(void)?

{?

int n;?

char *str = "1234";?

n = atoi(str);?

printf("string = %s integer = %d\n", str, n);?

return 0;?

}?

運行結果是:

string =1234 integer=1234

函數名: atof?

功 能: 把字符串轉換成浮點數?

用 法: double atof(const char *nptr);?

程序例:?

#include <stdlib.h>?

#include <stdio.h>?

int main(void)?

{?

float f;?

char *str = "12345.67";?

f = atof(str);?

printf("string = %s float = %f\n", str, f);?

return 0;?

}