主题:怎样将嵌套链表写入文件,然后再按要求把里面的值搜出来?
这个程序想起来其实也很简单,就是把数据赋给几个嵌套的链表,再写进文件,再按要求把文件中的数据找出来。
链表如下:
typedef struct tagTAliasRow
{
char szAlias[255];
char szAddress[16];
char *lpszDescription;
bool bSelected;
tagTAliasRow *pNext;
tagTAliasRow *pPrevious;
}TAliasRow;
//单个变量定义表的对应内部数据结构
typedef struct tagTAliasTable
{
bool bSelected;
char szTableName[255]; //用来存储表名
struct tagTAliasRow *pAliasRows;
tagTAliasTable *pNext;
tagTAliasTable *pPrevious;
}TAliasTable;
//变量定义表的对应内部数据结构
typedef struct tagTAlias
{ char szPassword[32];
struct tagTAliasTable *pFirst;
}TAlias;
//---------------------------------------------------------------------------------------------
然后数据在文件中的存储格式像下面的样子:
0x02
+szTableName
+0x01+szAlias+0x00+szAddress+0x00+lpszDescription
+0x01+szAlias+0x00+szAddress+0x00+lpszDescription
+0x01+szAlias+0x00+szAddress+0x00+lpszDescription
+0x02
+szTableName
+0x01+szAlias+0x00+szAddress+0x00+lpszDescription
+0x01+szAlias+0x00+szAddress+0x00+lpszDescription
+0x01+szAlias+0x00+szAddress+0x00+lpszDescription
+0x01+szAlias+0x00+szAddress+0x00+lpszDescription
0x02为表分隔符
0x01为行分隔符
0x00为字符间分隔符
程序的介面如下:
[img]http://p.blog.csdn.net/images/p_blog_csdn_net/sweetch/79376/o_%e7%aa%97%e5%8f%a3.JPG[/img]
大概的功能是这样的
1、点“打开文件”按钮,选择要打开的文件,把文件中"szTableName"的部份搜出来显示在ComboBox中,如果没有则为空。
2、在ComboBox中输入表名,点“添加”按钮,就把这个表加入文件中,表名不能重复
3、输入行号后,点“写到表中”就把szAlias、szAddress、lpszDescription的值写到ComboBox显示的那个表中的那一行中。
4、点“保存文件”按钮就把这些数据写到文件中。
链表如下:
typedef struct tagTAliasRow
{
char szAlias[255];
char szAddress[16];
char *lpszDescription;
bool bSelected;
tagTAliasRow *pNext;
tagTAliasRow *pPrevious;
}TAliasRow;
//单个变量定义表的对应内部数据结构
typedef struct tagTAliasTable
{
bool bSelected;
char szTableName[255]; //用来存储表名
struct tagTAliasRow *pAliasRows;
tagTAliasTable *pNext;
tagTAliasTable *pPrevious;
}TAliasTable;
//变量定义表的对应内部数据结构
typedef struct tagTAlias
{ char szPassword[32];
struct tagTAliasTable *pFirst;
}TAlias;
//---------------------------------------------------------------------------------------------
然后数据在文件中的存储格式像下面的样子:
0x02
+szTableName
+0x01+szAlias+0x00+szAddress+0x00+lpszDescription
+0x01+szAlias+0x00+szAddress+0x00+lpszDescription
+0x01+szAlias+0x00+szAddress+0x00+lpszDescription
+0x02
+szTableName
+0x01+szAlias+0x00+szAddress+0x00+lpszDescription
+0x01+szAlias+0x00+szAddress+0x00+lpszDescription
+0x01+szAlias+0x00+szAddress+0x00+lpszDescription
+0x01+szAlias+0x00+szAddress+0x00+lpszDescription
0x02为表分隔符
0x01为行分隔符
0x00为字符间分隔符
程序的介面如下:
[img]http://p.blog.csdn.net/images/p_blog_csdn_net/sweetch/79376/o_%e7%aa%97%e5%8f%a3.JPG[/img]
大概的功能是这样的
1、点“打开文件”按钮,选择要打开的文件,把文件中"szTableName"的部份搜出来显示在ComboBox中,如果没有则为空。
2、在ComboBox中输入表名,点“添加”按钮,就把这个表加入文件中,表名不能重复
3、输入行号后,点“写到表中”就把szAlias、szAddress、lpszDescription的值写到ComboBox显示的那个表中的那一行中。
4、点“保存文件”按钮就把这些数据写到文件中。