jak w temacie
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <ctype.h>
#include <string.h>
int main()
{
const char * test[] = {
"007", "AS504M", "as", "2147483647iNT", "unsigned4294967295long",
"922337203long long6854775807", "unsigned184long467440737long09551615",
"Wow99999999999999999999999999999999999999999999", "00Os9Yeah20"
};
int test_size = ((unsigned)(sizeof(test) / sizeof(test[0]) ) );
for(int i=0; i<test_size; ++i)
{
printf("str: %s\n",test[i]);
int size = strlen(test[i]);
const char *tmp = test[i];
char *t = (char *)malloc(sizeof(char)*size);
if(t == NULL) {
printf("Error! memory not allocated.");
exit(0);
}
for(int i=0, j=0; i<strlen(tmp); ++i) {
if(tmp[i]>='0' && tmp[i]<='9'){
//if(isdigit(tmp[i])){
t[j]=tmp[i];
++j;
}
}
printf("str: %s\n",t);
unsigned long ul = strtoul(t, &t, 10);
if(ul==ULONG_MAX) {
printf("num: overflow\n");
} else {
printf("num: %ld\n", ul);
}
printf("\n");
free(*t); // How Free a block allocated by 'malloc'
}
printf("\n\n");
return 0;
}