69,377
社区成员
发帖
与我相关
我的任务
分享
struct Column
{
int datatype; // 用以标示数据类型
int datalength; // 标示数据的长度
char name[128]; // or char *name;
struct Column *nextColumn;
struct data *firstData;
};
struct data
{
char *record;
struct data *nextdata;
};
void quit();
void import();
int main();
void print();
struct Column *bighead;//这里就是那个全局变量。
struct Column *creat();
#include<stdio.h>
#include<windows.h>
#include"struct.h"
int main()
{
int i;
char c;
printf(" ");
for(i=0;i<42;i++)
printf("*");
printf("\n");
printf(" * Tiny In-Mem DataBase version 6.72f *\n");
printf(" * Copyright X X ALL Rights Reserved *\n");
printf(" ");
for(i=0;i<42;i++)
printf("*");
printf("\nDB1=>");
while(1)
{scanf("%c",&c);
if(c=='-')
{scanf("%c",&c);
switch(c)
{
case'c':bighead=creat();break;//这一引用了全局变量。
case'i':import();break;
case's':break;
case'u':break;
case'd':break;
case'q':quit();return(0);
default :break;
}
}
else printf("Unavilable command!\n");
}
return(0);
}
#include<stdio.h>
#include<string.h>
#include <stdlib.h>
#include"struct.h"
void import()
{
FILE *fp;
char addr[20],ch,h[10];
scanf("%s",&addr);
fp=fopen(addr,"rt+");
ch=fgetc(fp);
struct data *p1,*p2,*p3,*p4,*p5,*p6;
struct Column *head;
p1=(struct data *)malloc(sizeof(struct data));
p3=(struct data *)malloc(sizeof(struct data));
p5=(struct data *)malloc(sizeof(struct data));
head=bighead;//.........................................就这里了。。
head->firstData = p1;
head=head->nextColumn;
head->firstData = p3;
head=head->nextColumn;
head->firstData = p5;
memset(h, 0, sizeof(h));
int i=0;
while(ch!=',')
{
h[i]=ch;
ch=fgetc(fp);
i++;
}
p1->record=h;
}
struct Column
{
int datatype; // 用以标示数据类型
int datalength; // 标示数据的长度
char name[128]; // or char *name;
struct Column *nextColumn;
struct data *firstData;
};
extern struct Column *bighead;
struct Column *creat();
struct data
{
char *record;
struct data *nextdata;
};
void quit();
void import();
int main();
void print();
#include<stdio.h>
#include<string.h>
#include <stdlib.h>
#include"struct.h"
struct Column *creat()
{
struct Column *head,*p1,*p2;
struct Column *bighead;//这里声明。。。。。。。。。。。。。。。。。
p1=p2=(struct Column *)malloc(sizeof(struct Column));
printf("you are right\n");
int n=0;
FILE *fp;
char addr[20],ch,h[10];
scanf("%s",&addr);
fp=fopen(addr,"rt+");
ch=fgetc(fp);
while(ch!='(')
{
printf("%c",ch);
ch=fgetc(fp);
}
ch=fgetc(fp);
ch=fgetc(fp);
printf("%c\n",ch);
int i=0;
memset(p1->name, 0, sizeof(p1->name));//字符串数组清零
while(ch!=' ')
{
p1->name[i]=ch;
ch=fgetc(fp);
i++;
}
printf("%s\n",p1->name);
ch=fgetc(fp);
if(ch=='f')p1->datatype=1;
else p1->datatype=0;
while(ch!='(')
{
ch=fgetc(fp);
}
i=0;
memset(h, 0, sizeof(h));
ch=fgetc(fp);
while(ch!=')')
{
h[i]=ch;
i++;
ch=fgetc(fp);
}
ch=fgetc(fp);
p1->datalength=atoi(h);
p1->firstData=NULL;
while(ch!=')')
{
n=n+1;
if(n==1)head=p1;
else p2->nextColumn=p1;
p2=p1;
p1=(struct Column *)malloc(sizeof(struct Column));
while(ch!=10)//进入下一行读取
{
ch=fgetc(fp);
}
ch=fgetc(fp);
if(ch==')')break;
memset(p1->name, 0, sizeof(p1->name));//输入名
i=0;
while(ch!=' ')
{
p1->name[i]=ch;
ch=fgetc(fp);
i++;
}
ch=fgetc(fp);
if(ch=='f')p1->datatype=1;//输入类型
else p1->datatype=0;
while(ch!='(')
{
ch=fgetc(fp);
}
i=0;
memset(h, 0, sizeof(h));//输入长度
ch=fgetc(fp);
while(ch!=')')
{
h[i]=ch;
i++;
ch=fgetc(fp);
}
p1->datalength=atoi(h);
p1->firstData=NULL;
ch=fgetc(fp);
}
p2->nextColumn=NULL;
struct Column *p;
printf("\nprint result is\n");
p=head;
if(head!=NULL)
while(p!=NULL)
{
printf("%d %d %5s\n",p->datatype,p->datalength,p->name);
p=p->nextColumn;
}
return(head);
}