I have checked my output with staff output using diff function and was getting same output although the first time I ran check50 it gave ":(" to all conditons except the existing and compiling ones and after that when I am running check50 it shows unexpected end of input. I have read other answer about unexpected end of Input according to which problem is from their side although I cannor figure out why check50 is giving error for all conditions even when I am getting correct output with diff function. Please Help. Code for reference :
#include <stdbool.h>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
long sizeofd=0;
#include "dictionary.h"
typedef struct node
{
char name[LENGTH+1];
struct node* next;
}node;
node* root[26];
/**
* Returns true if word is in dictionary else false.
*/
bool check(const char* word)
{
char word1[LENGTH+1];
for(int i=0;i<strlen(word);i++)
{
word1[i] = tolower(word[i]);
}
word1[strlen(word)]='\0';
int index=word1[0]-'a';
if(!root[index])
return false;
if(!strcmp(root[index]->name,word1))
{
return true;
}
else
{node*temp2=root[index];
while((temp2->next))
{ temp2=temp2->next;
if(!strcmp(temp2->name,word1))
{
return true;
}
}
if(!strcmp(temp2->name,word1))
{
return true;
}
}
return false;
}
/**
* Loads dictionary into memory. Returns true if successful else false.
*/
bool load(const char* dictionary)
{
int ii=0;
while(ii<26)
{
root[ii] = malloc(sizeof(node));
root[ii] = NULL;
ii++;
}
FILE* file = fopen(dictionary,"r");
if(!file)
{
return false;
}
char c;
char nm[LENGTH+1];
int i=0,index;
while((c = fgetc(file)) != EOF)
{
if(i==0)
strcpy(nm,"");
if(c!='\n')
{
nm[i]=c;
i++;
}
else
{
nm[i]='\0';
i=0;
index=nm[0]-'a';
if(!root[index])
{
node* temp=malloc(sizeof(node));
// temp=malloc(sizeof(node));
root[index]=temp;
strcpy(root[index]->name,nm);
sizeofd++;
root[index]->next=NULL;
// free(temp);
}
else
{
// temp=malloc(sizeof(node));
node*temp1=root[index];
while(temp1->next!=NULL)
{
temp1=temp1->next;
}
node* temp=malloc(sizeof(node));
strcpy(temp->name,nm);
temp1->next=temp;
temp->next=NULL;
sizeofd++;
// free(temp1);
// free(temp);
}
}
}
fclose(file);
return true;
}
/**
* Returns number of words in dictionary if loaded else 0 if not yet loaded.
*/
unsigned int size(void)
{
return sizeofd;
}
/**
* Unloads dictionary from memory. Returns true if successful else false.
*/
bool unload(void)
{
for(int i=0;i<26;i++)
{
node* temp=root[i];
if(temp->next==NULL)
{
free(temp);
continue;
}
while(temp->next!=NULL)
{
node* temp1=temp;
temp=temp->next;
free(temp1);
}
}
return(true);
}