#include <stdio.h>
#define MAXLSFNAMELEN 256
#define MAXMODEL 256
#define TRUE 1
#define FALSE 0
typedef struct HostModel
{
char **HostModelName;
int nModel;
}HostModel;
typedef struct HostLsModel
{
char **HostModelName;
int nModel;
}HostLsModel;
HostModel allInfo;
HostLsModel shortInfo;
int AddHostModel(char* model)
{
int i;
static int iNum = 0;
if(model == NULL)
{
return FALSE;
}
if(!allInfo.HostModelName)
{
allInfo.HostModelName = (char**)malloc(sizeof(char*) * MAXMODEL);
if(!allInfo.HostModelName)
{
return FALSE;
}
shortInfo.HostModelName = (char**)malloc(sizeof(char*) * MAXMODEL);
if(!shortInfo.HostModelName)
{
return FALSE;
}
for(i=0; i<MAXMODEL; i++)
{
allInfo.HostModelName[i] = (char*)malloc(sizeof(char)*MAXLSFNAMELEN);
if(!allInfo.HostModelName[i])
{
return FALSE;
}
}
}
if(iNum < MAXMODEL)
{
strcpy(allInfo.HostModelName[iNum], model);
shortInfo.HostModelName[iNum] = allInfo.HostModelName[iNum];
iNum++;
}
else
{
allInfo.HostModelName = (char**)realloc(allInfo.HostModelName, sizeof(char*)*(iNum + 1));
if(!allInfo.HostModelName)
{
return FALSE;
}
shortInfo.HostModelName = (char**)realloc(shortInfo.HostModelName, sizeof(char*)*(iNum + 1));
if(!shortInfo.HostModelName)
{
return FALSE;
}
allInfo.HostModelName[iNum] = (char*)malloc(sizeof(char)*MAXLSFNAMELEN);
if(!allInfo.HostModelName[iNum])
{
return FALSE;
}
strcpy(allInfo.HostModelName[iNum], model);
shortInfo.HostModelName[iNum] = allInfo.HostModelName[iNum];
iNum++;
}
allInfo.nModel = iNum;
shortInfo.nModel = iNum;
return TRUE;
}
int main()
{
int i;
for(i=0; i<MAXMODEL; i++)
{
AddHostModel("Same");
}
AddHostModel("Fir");
AddHostModel("Sec");
AddHostModel("Thrd");
AddHostModel("Forth");
for(i=0; i<shortInfo.nModel; i++)
{
printf("HostName%d: %s/n", i + 1, shortInfo.HostModelName[i]);
}
return 0;
}