Code:
while(fgets(line,Char,que)!=NULL && strcmp(line,"quit") !=0)//when the command is not eof
{
strcpy(curline,line);
// printf("curline= %s\n",curline);
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;
printf("curline in count = %s\n", curline);
token1 = strtok(curline, " \r\t\n");//use strtok to get the first word
while(token1 != NULL)
{
printf("token1 %s\n",token1);
token1 = strtok (NULL, " \r\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;
}
I made few changes so it looks more clearly
output:
unix2% p3 config_file.txt query_file.txt
calling count
curline in count = count Students
token1 count
token1 Students
end of token
size = 2
str= Students
Segmentation Fault (core dumped)
thanks guys I found the error haha finally beat it!!!
the error is token == NULL after strtok is over and you cant print or compare it lol what a stupid mistake