#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_NAME_LENGTH (10)
typedef struct FooImpl* Foo;
typedef struct FooImpl {
int Number;
int Score;
char* Name;
} FooImpl;
Foo Foo_Init(int Number, int Score, const char* Name)
{
Foo f
= (Foo
)malloc(sizeof(FooImpl
)); f->Number = Number;
f->Score = Score;
if (strlen(Name
) > MAX_NAME_LENGTH
) { return NULL;
}
return f;
}
void Foo_Delete(Foo f)
{
if (!f)
return;
}
void Foo_Print(Foo f, const char* Name)
{
if (strncmp(f
->Name
, Name
, MAX_NAME_LENGTH
) != 0) return;
fprintf(stdout
, "Number: %i, Score: %i, Name: %s", f
->Number
, f
->Score
, f
->Name
); }
int main(void)
{
Foo f[2];
int i;
char input[MAX_NAME_LENGTH];
f[0] = Foo_Init(1, 10, "Yamada");
f[1] = Foo_Init(2, 20, "Yoshida");
for (i=0; i<sizeof(f)/sizeof(Foo); i++) {
Foo_Print(f[i], input);
Foo_Delete(f[i]);
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKI2RlZmluZSBNQVhfTkFNRV9MRU5HVEggKDEwKQoKdHlwZWRlZiBzdHJ1Y3QgRm9vSW1wbCogRm9vOwoKdHlwZWRlZiBzdHJ1Y3QgRm9vSW1wbCB7CiAgaW50IE51bWJlcjsKICBpbnQgU2NvcmU7CiAgY2hhciogTmFtZTsKfSBGb29JbXBsOwoKRm9vIEZvb19Jbml0KGludCBOdW1iZXIsIGludCBTY29yZSwgY29uc3QgY2hhciogTmFtZSkKewogIEZvbyBmID0gKEZvbyltYWxsb2Moc2l6ZW9mKEZvb0ltcGwpKTsKICBmLT5OdW1iZXIgPSBOdW1iZXI7CiAgZi0+U2NvcmUgPSBTY29yZTsKICBpZiAoc3RybGVuKE5hbWUpID4gTUFYX05BTUVfTEVOR1RIKSB7CiAgICBmcmVlKGYpOwogICAgcmV0dXJuIE5VTEw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