作者lgen7604 ()
看板C_and_CPP
標題Re: [問題] 字串轉二進位整數
時間Sat May 8 18:52:21 2010
C 的 strto?? 我覺得也滿好用的
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (void) {
char str[80];
char *endptr;
int i;
printf("Enter a string for long int conversion: ");
gets(str);
i = strtol(str, &endptr, 2);
if (endptr == str)
printf("That is not a valid string\n");
else {
printf("The converted int is %d\n", i);
if (strlen(endptr) != 0)
printf("The remaining string from your input is \"%s\"\n", endptr);
}
return 0;
}
Reference:
http://www.digitalmars.com/rtl/stdlib.html#strtol
--
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.120.46.89
推 Dannvix:推! 05/08 18:55
推 loveme00835:似層相似的感覺 囧> 05/08 18:57
推 VictorTom:還真的不認識這個函數XD 05/08 23:04