Code:
while(fgets(line,Char,que)!=NULL && strcmp(line,"quit") !=0)//when the command is not eof
{
strcpy(curline,line);
token1=strtok(line," \n\t");//get the command
while(token1 != NULL)//when command is not quit
{
if(strcmp("count",token1) ==0)//when command is count
{
printf("calling count\n");
fflush(stdout);
count();//call count
printf("called count\n");
fflush(stdout);
}
Code:
void count(void)//the founction print out the number of relations
{
char * token1;
// char * attname;
char * str;
int size;
int x =0;
int right =0;
token1 = strtok(curline, " \t\n");//use strtok to get the first word
printf("token1 = %s\n", token1);
while(token1 != NULL)
{
token1 = strtok (NULL, " \t\n");//continue to part the string
}
printf("end of token\n");
size =tableSize;//set size
printf("size = %d\n",size);
while(size>0 && right == 0)//if size is>0 and right is 0
{
str = relation[x].name;
printf("str= %s\n",str);
printf("token1= %s\n",token1);
printf("1");
if((strcmp(str,token1))==0)
{
printf("in strcmp\n");
fflush(stdout);
printf("There are %d of tuples in this relation. \n", schLine);//print
right =1;
}
.
.
.
files compiled and the
output:
calling count
token1 = count
end of token
size = 2
str= Students
Segmentation Fault (core dumped)
all those codes are part of the file. I would like to show more if it is needed.
char curline[100];