C言語なら、俺に聞け! <26>
■ このスレッドは過去ログ倉庫に格納されています
0290デフォルトの名無しさん
NGNG以下長文スマソ
#include <stdio.h>
#include <stdlib.h>
struct Test{
int *test01;
char *test02;
};
struct Test *
Test3_new()
{
struct Test *test = (struct Test *) calloc( 3, sizeof(struct Test) );
int i;
for ( i = 0; i < 3; i++ ) {
test[i].test01 = (int *) calloc( 1, sizeof(int) );
test[i].test02 = (char *) calloc( 2, sizeof(char) );
}
return test;
}
int main ()
{
int i;
struct Test *test;
test = Test3_new();
*(test[0].test01) = 10;
test[0].test02[0] = 'a';
test[0].test02[1] = '\0';
*(test[1].test01) = 20;
test[1].test02[0] = 'b';
test[1].test02[1] = '\0';
*(test[2].test01) = 30;
test[2].test02[0] = 'c';
test[2].test02[1] = '\0';
for (i=0; i<3; i++) {
printf("%d %s\n", *(test[i].test01), test[i].test02);
}
return 0;
}
■ このスレッドは過去ログ倉庫に格納されています