国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

將字符串轉換為數字

2019-11-11 05:14:05
字體:
來源:轉載
供稿:網友

下列函數可以將字符串轉換為數字:

函數名 作 用

atof() 將字符串轉換為雙精度浮點型值 atoi() 將字符串轉換為整型值 atol() 將字符串轉換為長整型值 strtod() 將字符串轉換為雙精度浮點型值,并報告不能被轉換的所有剩余數字 strtol() 將字符串轉換為長整值,并報告不能被轉換的所有剩余數字 strtoul() 將字符串轉換為無符號長整型值,并報告不能被轉換的所有剩余數字

/* strtod example */#include <stdio.h> /* PRintf, NULL */#include <stdlib.h> /* strtod */int main (){ char szOrbits[] = "365.24 29.53"; char* pEnd; double d1, d2; d1 = strtod (szOrbits, &pEnd); d2 = strtod (pEnd, NULL); printf ("The moon completes %.2f orbits per Earth year./n", d1/d2); return 0;}/* strtol example */#include <stdio.h> /* printf */#include <stdlib.h> /* strtol */int main (){ char szNumbers[] = "2001 60c0c0 -1101110100110100100000 0x6fffff"; char * pEnd; long int li1, li2, li3, li4; li1 = strtol (szNumbers,&pEnd,10); li2 = strtol (pEnd,&pEnd,16); li3 = strtol (pEnd,&pEnd,2); li4 = strtol (pEnd,NULL,0); printf ("The decimal equivalents are: %ld, %ld, %ld and %ld./n", li1, li2, li3, li4); return 0;}/* strtoul example */#include <stdio.h> /* printf, NULL */#include <stdlib.h> /* strtoul */int main (){ char buffer [256]; unsigned long ul; printf ("Enter an unsigned number: "); fgets (buffer, 256, stdin); ul = strtoul (buffer, NULL, 0); printf ("Value entered: %lu. Its double: %lu/n",ul,ul*2); return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 县级市| 车险| 阳山县| 丹巴县| 茶陵县| 准格尔旗| 桓台县| 英吉沙县| 奇台县| 慈利县| 呼图壁县| 福清市| 南岸区| 平邑县| 平顶山市| 富顺县| 宁强县| 信宜市| 双城市| 兴城市| 贞丰县| 双鸭山市| 三河市| 澄迈县| 沙河市| 莒南县| 伊川县| 东光县| 慈溪市| 南召县| 乡城县| 周至县| 海晏县| 贺兰县| 八宿县| 博湖县| 新巴尔虎左旗| 仙游县| 黄陵县| 府谷县| 沙田区|