- 914 名前:デフォルトの名無しさん mailto:sage [2010/03/14(日) 23:34:08 ]
- #include <stdio.h>
#include <stdlib.h> #include <string.h> typedef struct TestData { int id; char *name; char *sp; char *sx; int nr_param; char *param; } TestData; #define PARA(max,at,sp) ":" #max "," #at "," #sp static TestData test_array[] = { { 1, "NA", "SpA", "M", 3, PARA(0, 0, 1) PARA(2, 3, 4) PARA(5, 6, 7), }, { 2, "NB", "SpB", "???", 1, PARA(1, 2, 3), }, }; void dump_testdata(TestData *t) { int i; const char *p; printf(" Id:%d, Name:%s, Sp:%s, Sx:%s\n", t->id, t->name, t->sp, t->sx); p = t->param; for ( i = 0; i < t->nr_param ;i++) { int m, a, s; m = atoi(p = strchr(p, ':')+1); a = atoi(p = strchr(p, ',')+1); s = atoi(p = strchr(p, ',')+1); printf(" param: max:%d, attack:%d, speed:%d\n", m, a, s); } } int main(void) { dump_testdata(&test_array[0]); dump_testdata(&test_array[1]); return 0; }
|

|