⑴ linux中atoi是什麼函數
標准C庫函數
#include <stdlib.h>
原型 : int atoi( const char *str );
功能:將字元串str轉換成一個整數並返回結果。參數str 以數字開頭,版當函數從str
中讀到非權數字字元則結束轉換並將結果返回。
例如:int num = atoi("1314.012");
int值為1314
⑵ linux下用c程序獲取字元串中的字元串。strstr以及int到char指針的強制類型轉換
len = ((char *)(&(system("ifconfig eth0")))); 這行&去掉就可以了
調用system返回int,直接可以進行強轉
⑶ 在linux下編程如何使用字元串流將字元串類型轉換成int型
int sprintf(char *STR, const char *FORMAT, ...);
或者直接int atoi(const char *S);
或者int _atoi_r(struct _reent *PTR, const char *S);
⑷ 函數atoi()有什麼用處,他的頭文件是什麼它在Linux下的Vi編輯器能用嗎
1、atoi (表示 ascii to integer)是把字元串轉換成整型數的一個函數,應用在計算機程序和辦公軟體中。
2、頭文件: #include <stdlib.h>
3、它在Linux下的Vi編輯器能用
int atoi(const char *nptr) 函數會掃描參數 nptr字元串,會跳過前面的空白字元(例如空格,tab縮進)等。如果 nptr不能轉換成 int 或者 nptr為空字元串,那麼將返回 0 。特別注意,該函數要求被轉換的字元串是按十進制數理解的。
(4)linux字元串轉換為int擴展閱讀
範例:
1>
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
int n;
char *str = "12345.67";
n = atoi(str);
printf("string = %s integer =%d ", str, n);
return 0;
}
執行結果
string = 12345.67 integer = 12345.000000
2>
#include <stdlib.h>
#include <stdio.h>
int main()
{
char a[] = "-100" ;
char b[] = "123" ;
int c ;
c = atoi( a ) + atoi( b ) ;
printf("c = %d ", c) ;
return 0;
}
執行結果
c = 23
參考資料來源:網路—atoi()
⑸ linux下如何將整形轉化為字元串
有如下兩種常用方法。
一、可以通過調用C庫函數itoa實現。
1 原型。
char*itoa(int value,char*string,int radix);
2 頭文件。
stdlib.h
3 功能。
將value的值,轉換為字元串,並存到string中,如果轉化後的字元串長度超過radix,那麼只存radix位。
4 樣例。
int i=1234;
char buf[10];
itoa(i, buf, 10);
執行後buf內容為字元串"1234"。
二、通過sprintf格式化輸出到字元串中。
itoa並不是C語言標准庫函數,所以並不是每個平台均支持該函數。當不支持時,可以用sprintf函數來達到同樣效果。
1 原型。
int sprintf( char *buffer, const char *format, [ argument] … );
2 頭文件。
stdio.h
3 功能。
類似於printf,根據格式化字元串format,將後續參數列表中的參數逐個輸出。不過輸出目標不是標准輸出終端,而是字元串buffer。
4 樣例。
int i=1234;
char buf[10];
sprintf(buf,"%d",i);
執行後buf內容同樣為字元串"1234"。