#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
char *end;
printf("\" 999999999999999999999999999999999999999999999\" em decimal --> %ld - ", strtol(" 999999999999999999999999999999999999999999999", &end
, 10)); printf("\"1010\" em binário --> %ld\n", strtol("1010", NULL
, 2)); //sem tratamento de erro printf("\"junk\" em base 36 --> %ld\n", strtol("junk", NULL
, 36)); printf("\"012\" detecção --> %ld\n", strtol("012", NULL
, 0)); printf("\"0xA\" detecção --> %ld\n", strtol("0xA", NULL
, 0)); printf("\"junk\" detecção --> %ld - ", strtol("junk", &end
, 0)); }
//http://pt.stackoverflow.com/q/185345/101
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxlcnJuby5oPgojaW5jbHVkZSA8c3RkbGliLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KIAppbnQgbWFpbih2b2lkKSB7CgljaGFyICplbmQ7CiAgICBwcmludGYoIlwiIDk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OVwiIGVtIGRlY2ltYWwgLS0+ICVsZCAtICIsIHN0cnRvbCgiIDk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OSIsICZlbmQsIDEwKSk7CiAgICBwcmludGYoIkVycm86ICVzXG4iLCBzdHJlcnJvcihlcnJubykpOwogICAgcHJpbnRmKCJcIjEwMTBcIiBlbSBiaW7DoXJpbyAtLT4gJWxkXG4iLCBzdHJ0b2woIjEwMTAiLCBOVUxMLCAyKSk7IC8vc2VtIHRyYXRhbWVudG8gZGUgZXJybwogICAgcHJpbnRmKCJcIjEyXCIgZW0gb2N0YWwgICAgIC0tPiAlbGRcbiIsIHN0cnRvbCgiMTIiLCBOVUxMLCA4KSk7CiAgICBwcmludGYoIlwiQVwiICBlbSBoZXggICAgICAgLS0+ICVsZFxuIiwgc3RydG9sKCJBIiwgTlVMTCwgMTYpKTsKICAgIHByaW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