#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
#define TABLE_MAX_LENGH 1000
#define FIELD_MAX_LENGH 256
#define NAME_MAX_LENGH 100
#define DATA_MAX_LETH 1000
#define MAX_LINE 2048
#define MAX_SUBSTRINGS 100
typedef struct field field;
typedef struct record record;
typedef struct table table;
typedef struct fieldList fieldList;
typedef struct recordList recordList;
typedef struct tableArray tableArray;
enum item_type {
INTEGER = 0,
STRING = 1
};
typedef struct field {
enum item_type type;
char name[NAME_MAX_LENGH];
char data[DATA_MAX_LETH];
bool is_key;
field * next;
};
typedef struct record {
fieldList * field_list;
record* next;
};
typedef struct table {
char key[NAME_MAX_LENGH];
recordList* record_list;
};
typedef struct fieldList {
field head;
int length;
};
typedef struct recordList {
record head;
int length;
};
typedef struct tableArray {
table* Table;
int length;
};
void printFixedLengthString(const char* str) {
size_t len = strlen(str);
if (len <= 10) {
// 字符串长度小于等于最大长度,直接输出并在末尾填充
printf("%.*s%*c\t", (int)len, str, 10 - len, ' ');
}
else {
// 字符串长度大于最大长度,截取前maxLength个字符并输出
printf("%.10s\t", str);
}
}
fieldList* fieldList_init(void) {
fieldList* pList = (fieldList*)malloc(sizeof(fieldList));
if (pList == NULL) {
return NULL;
}
pList->head.next = NULL;
pList->length = 0;
return pList;
}
void fieldList_add(fieldList* pList,int index, field* pField) {
if(pList==NULL||pField==NULL){
return;
}
if (index < 0 || index > pList->length) {
index = pList->length;
}
//
field* tmp = &pList->head;
for (int i = 0; i < index; i++)
{
tmp = tmp->next;
}
pField->next = tmp->next;
tmp->next = pField;
pList->length++;
}
//遍历
void forEach_fieldList(fieldList* list) {
if (list == NULL) {
return;
}
field* tmp = list->head.next;
for (size_t i = 0; i < list->length; i++)
{
//printf("%s\n", tmp->data);
printFixedLengthString(tmp->data);
tmp = tmp->next;
}
}
//按位置删
void fieldList_removeByindex(fieldList* list, int index) {
if (list == NULL) {
return;
}
if (index<0 || index>list->length) {
return;
}
field* tmp = &list->head;
for (int i = 0; i < index; i++)
{
tmp = tmp->next;
}
//记录待删除节点
field* pDel = tmp->next;
//重新建立关系
tmp->next = tmp->next->next;
//删除节点
free(pDel);
pDel = NULL;
//更新链表长度
list->length--;
}
void fieldList_clear(fieldList* list) {
size_t length = list->length;
for (size_t i = 0; i < length; i++)
{
fieldList_removeByindex(list, 0);
}
free(list);
list = NULL;
}
recordList* recordList_init(void) {
recordList* pList = (recordList*)malloc(sizeof(recordList));
if (pList == NULL) {
return NULL;
}
pList->head.next = NULL;
pList->length = 0;
return pList;
}
void recordList_add(recordList* pList, int index, record* pRecord) {
if (pList == NULL || pRecord == NULL) {
return;
}
if (index < 0 || index > pList->length) {
index = pList->length;
}
//
record* tmp = &pList->head;
for (int i = 0; i < index; i++)
{
tmp = tmp->next;
}
pRecord->next = tmp->next;
tmp->next = pRecord;
pList->length++;
}
//遍历
void forEach_recordList(recordList* list) {
if (list == NULL) {
return;
}
record* tmp = list->head.next;
for (size_t i = 0; i < list->length; i++)
{
printf_s("record %d\n", i);
forEach_fieldList(tmp->field_list);
printf_s("\n");
tmp = tmp->next;
}
}
void recordList_removeByindex(recordList* list, int index) {
if (list == NULL) {
return;
}
if (index<0 || index>list->length) {
return;
}
record* tmp = &list->head;
for (int i = 0; i < index; i++)
{
tmp = tmp->next;
}
//记录待删除节点
record* pDel = tmp->next;
//重新建立关系
tmp->next = tmp->next->next;
//删除子节点
fieldList_clear(pDel->field_list);
//删除节点
free(pDel);
pDel = NULL;
//更新链表长度
list->length--;
}
tableArray* tableArray_init() {
tableArray* TableArray = (tableArray*)malloc(sizeof(tableArray));
TableArray->length = 0;
TableArray->Table = (table*)malloc(TABLE_MAX_LENGH * sizeof(table));
return TableArray;
}
void tableArray_add(tableArray* TableArray,table* Table) {
if (TableArray == NULL) {
return;
}
if (TableArray->length >= TABLE_MAX_LENGH) {
return;
}
TableArray->Table[TableArray->length] = *Table;
TableArray->length++;
}
void printTableTitle(table* Table) {
fieldList* field_list= Table->record_list->head.next->field_list;
if (field_list == NULL) {
return;
}
size_t length = field_list->length;
field* tmp = field_list->head.next;
for (size_t i = 0; i < length; i++)
{
printFixedLengthString(tmp->name);
tmp = tmp->next;
}
}
//遍历
void forEach_tableArray(tableArray* TableArray) {
if (TableArray == NULL) {
return;
}
for (size_t i = 0; i < TableArray->length; i++)
{
printf_s("table %d\n", i);
printTableTitle(&TableArray->Table[i]);
printf_s("\n");
forEach_recordList(TableArray->Table[i].record_list);
}
}
void test_api() {
printf_s("--------------test_field--------------\n");
////field
fieldList* pList = fieldList_init();
//add 1
field* newField = (field*)malloc(sizeof(field));
strcpy_s(newField->data, 100, "写代码");
newField->next = NULL;
strcpy_s(newField->name, 100, "爱好");
newField->type = INTEGER;
fieldList_add(pList, 0, newField);
//add 2
newField = (field*)malloc(sizeof(field));
strcpy_s(newField->data, 100, "软件学院");
newField->next = NULL;
strcpy_s(newField->name, 100, "院系");
newField->type = INTEGER;
fieldList_add(pList, 0, newField);
forEach_fieldList(pList);
printf_s("--------------insert field on 0 index end \n");
//remove 2
fieldList_removeByindex(pList, 0);
forEach_fieldList(pList);
printf_s("--------------remove field on 0 index end\n");
//add 2
newField = (field*)malloc(sizeof(field));
strcpy_s(newField->data, 100, "软件学院");
newField->next = NULL;
strcpy_s(newField->name, 100, "院系");
newField->type = INTEGER;
fieldList_add(pList, 0, newField);
forEach_fieldList(pList);
printf_s("--------------insert field on 0 index end \n");
printf_s("--------------test_record--------------\n");
//record 1
recordList* record_list = recordList_init();
record* pRecord=(record*)malloc(sizeof(record));
pRecord->next = NULL;
pRecord->field_list = pList;
recordList_add(record_list, 0, pRecord);
forEach_recordList(record_list);
printf_s("--------------add 1 record end\n");
//record 2
fieldList* pList_2 = fieldList_init();
//add 1
field* newField_2 = (field*)malloc(sizeof(field));
strcpy_s(newField_2->data, 100, "备课");
newField_2->next = NULL;
strcpy_s(newField_2->name, 100, "爱好");
newField_2->type = INTEGER;
fieldList_add(pList_2, 0, newField_2);
//add 2
newField_2 = (field*)malloc(sizeof(field));
strcpy_s(newField_2->data, 100, "技术科学实验班");
newField_2->next = NULL;
strcpy_s(newField_2->name, 100, "院系");
newField_2->type = INTEGER;
fieldList_add(pList_2, 0, newField_2);
record* pRecord_2 = (record*)malloc(sizeof(record));
pRecord_2->next = NULL;
pRecord_2->field_list = pList_2;
recordList_add(record_list, 0, pRecord_2);
forEach_recordList(record_list);
printf_s("--------------insert 1 record on index 0 end\n");
//remove record 1
recordList_removeByindex(record_list, 0);
forEach_recordList(record_list);
printf_s("--------------remove 1 record on index 0 end\n");
//add record 2 again
//record 2
pList_2 = fieldList_init();
//add 1
newField_2 = (field*)malloc(sizeof(field));
strcpy_s(newField_2->data, 100, "备课");
newField_2->next = NULL;
strcpy_s(newField_2->name, 100, "爱好");
newField_2->type = INTEGER;
fiel
没有合适的资源?快使用搜索试试~ 我知道了~
golang 关于核心的报错查询手册 包含错误代码
共1个文件
c:1个
需积分: 5 0 下载量 199 浏览量
2024-08-12
11:44:55
上传
评论
收藏 3KB ZIP 举报
温馨提示
golang 关于核心的报错查询手册 包含错误代码 【项目资源】:包含前端、后端、移动开发、操作系统、人工智能、物联网、信息化管理、数据库、硬件开发、大数据、课程资源、音视频、网站开发等各种技术项目的源码。包括STM32、ESP8266、PHP、QT、Linux、iOS、C++、Java、python、web、C#、EDA、proteus、RTOS等项目的源码。 【项目质量】:所有源码都经过严格测试,可以直接运行。功能在确认正常工作后才上传。 【适用人群】:适用于希望学习不同技术领域的小白或进阶学习者。可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。 【附加价值】:项目具有较高的学习借鉴价值,也可直接拿来修改复刻。对于有一定基础或热衷于研究的人来说,可以在这些基础代码上进行修改和扩展,实现其他功能。 【沟通交流】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。鼓励下载和使用,并欢迎大家互相学习,共同进步。
资源推荐
资源详情
资源评论
收起资源包目录
sim.zip (1个子文件)
sim.c 12KB
共 1 条
- 1
资源评论
聚财猫猫
- 粉丝: 248
- 资源: 221
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功