關於字符串轉整型的問題

字符串,轉成整型數字,用到一個函數atoi(const char *p)ide

char get_str()
{
char
a = "20";
return a;
}函數

int main(void)
{
char *str = NULL;
int vlaue;code

str = get_str();
 printf("str is %s\n", str);

 value = atoi(str);
 printf("value is %d\n", value);

  return 0;

}字符串

運行結果是:
str is 20
value is 20get

這樣就完美的把字符串「20」,轉成了整型數字20it

相關文章
相關標籤/搜索