1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| #include <stdlib.h>
#include <ctype.h>
#include <assert.h>
#include <stddef.h>
typedef struct
{
char* pattern;
int result;
} test_record;
test_record test_datas[] =
{
{"a1", 0},
{"1a", 0},
{"123", 1},
{"123 ", 0},
{"", 0},
{" 123", 0},
{NULL, 0}
};
int isnumerictext(char* text)
{
if(*text=='\0') return 0;
if (!isdigit(*text)) return 0;
while(1)
{
if(*text=='\0') return 1;
if (!isdigit(*text)) return 0;
text++;
}
}
int main(int argc, char **argv)
{
test_record* record_ptr = test_datas;
while(record_ptr->pattern != NULL)
{
printf("\"%s\" : %i\n", record_ptr->pattern, record_ptr->result);
assert(isnumerictext(record_ptr->pattern)==record_ptr->result);
record_ptr++;
}
return 0;
} |
Partager