ddl.h

来自「c语言编写的微型数据库 实现了插入、删除、更新等基本功能」· C头文件 代码 · 共 81 行

H
81
字号
#ifndef DDL_H
#define DDL_H 
#include "Glob_Var.H" 
#include "Std_Head.H" 
/* ------------------------------------------------------------------------------------------ */
/* 建一个空的表结构,其中包括一级元数据(记录长度,字段个数,记录总数)和 */
/* 二级元数据(各字段结构信息) */
Do_Create(CmdRec_Type CmdRec)
{
    FILE*fp ;  /* 指向数据文件的指针 */

    char TemName[20] = "";/* 存放添加后缀.txt的字符数组 */
    
    int i,j,Total=0,RecLen=0 ;
    
    int string[3] = {0,0,0};  /* 存放一级元数据 */

    clrscr();

    textbackground(BLUE);

    textcolor(YELLOW);

    strcpy(TemName,CmdRec.UserStr);
    
    strcat(TemName,".TXT");
    
    fp=fopen(TemName,"w+b"); /* 打开文件 */
    
    if(fp==NULL)printf("The file does not exist! ");
    
    /* 计算记录长度 */
 for(i=1;i<=CmdRec.Count;i++)

    {
        if(!strcmp("float",(CmdRec).Fld[i].FldClass))
        
        RecLen+=sizeof(float);
        
        else if(!strcmp("int",(CmdRec).Fld[i].FldClass))
        RecLen+=sizeof(int);
        
        else if(!strcmp("char",(CmdRec).Fld[i].FldClass))
        RecLen+=(CmdRec.Fld[i].FldLen);
    }

    string[0]=RecLen ; /* 记录长度 */

    string[1]=CmdRec.Count ;  /* 字段数 */

    string[2]=Total ;/* 记录总数 */

    fwrite(string,2,3,fp); /* 将一级元数据写入文件 */

 for(i=1;i<=CmdRec.Count;i++)/*  将二级元数据即各字段结构信息写入文件*/

    fwrite(&CmdRec.Fld[i],sizeof(struct FldInforStruct),1,fp);
    
  printf("Congratulations!Your create a blank table named %s.\n",CmdRec.UserStr);/* 显示刚建表的相关信息 */

  printf("\nThe Base Information are as follows:\n");

  printf("\n");

  printf("RecordLen:%d\n",string[0]);  printf("FldLen:%d\n",string[1]); printf("RecordNum:%d\n",string[2]);

  printf("\n");

  printf("FldName   FldClass  FldLen    DicimalLen  \n");

    for(i=1;i<=string[1];i++)
    {
        printf("%-10s%-10s%-10d%-12d\n",CmdRec.Fld[i].FldName,CmdRec.Fld[i].FldClass,CmdRec.Fld[i].FldLen,CmdRec.Fld[i].DicimalLen);

        printf("\n"); }
    
    fclose(fp);   /* 关闭文件 */
}
/* ---------------------------------------------------------------------------------------------- */
#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?