Hi All
I am creating program which will initialized structures for various record type and will call for N tables.
The structure will have info regarding the tables.
Since the init() function will called N times for N tables, so N structures will be created and I want them to store them in Array of structures.
The code is:
Code:
#include<stdio.h>
#include<conio.h>
#include <stddef.h>
char *colArr[]={"IDNAME","IDAGE"};
char *colType[]={"CHAR","INT"};
typedef struct
{
char colName[10];
char colType[10];
char colLen[10];
} colInfo;
typedef struct
{
char tableName[10];
int colCount;
colInfo *pCol;
} tableInfo;
tableInfo *tPtr[] = {0x00};
int fileCount = 0;
int init()
{
tableInfo tInfo;
int i;
memset(&tInfo,0x00,sizeof(tInfo));
tInfo.pCol = (tableInfo *)malloc(sizeof(tableInfo) * 2);
memcpy(tInfo.tableName,"IDTABLE",7);
tInfo.colCount = 2;
for (i = 0; i< tInfo.colCount ;i++)
{
memcpy(tInfo.pCol[i].colName,colArr[i],6);
memcpy(tInfo.pCol[i].colType,colType[i],4);
memcpy(tInfo.pCol[i].colLen,"4",1);
}
printf("%s\n",tInfo.tableName);
printf("%d\n",tInfo.colCount);
for (i = 0; i < tInfo.colCount;i++)
{
printf("%s\n",tInfo.pCol[i].colName);
printf("%s\n",tInfo.pCol[i].colType);
printf("%s\n",tInfo.pCol[i].colLen);
}
// Here I need info
tPtr[fileCount] =&tInfo;
fileCount++;
return 1;
}
The above is not working as when I memset, every thing vanish since second time call to memset delete everything.
Can any body help me in this regard so that I can store structures in array and values should not vanish.
Thanks
Nickman