0

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);
}
2

The issue is time. There's nothing wrong with the server for pset5. (Don't know if there are pset6 issues, but that's a different situation.) While your program may work, it is slow. When I ran your code, it was taking about 37 seconds to run with holmes.txt as input. That's on my system with minimal load and a solid state drive. Run it on a system with a standard hard drive with a spinning disk and it will be even slower. Add in any other system load, like the grading server, and the timesharing and parallel processing makes it even worse.

As a comparison, many programs run the same file in less than 1 second. Even a few seconds is good. Note that check50 has a time limit built into it, primarily to catch infinite loops. Your code is running up against that time limit, resulting in the unexpected end of input error. (If you run it repeatedly, sometimes it may complete, other times it will error out. This happens when the code being tested is running near the time limit and server load varies.)

If you look at the times, check() is taking the most time. That doesn't mean that it is the root cause of the problem. check could be slow because of the structure of the tree, which would put the problem in load. For example, there are more than 143,000 words in the dictionary. Your code puts them in 26 buckets in the tree. That means that the linked lists that start at those 26 buckets are going to be over 5000 nodes long, on average. That's a lot of searching to find the target. If there were, say, 10,000 buckets, that would mean the average linked list length would be about 15 and the search would run a whole lot faster. Maybe you need a better way to hash the words?

This program needs an efficiency review. You need to think about what is executing fast and what isn't. Think about disk reads, about loops, etc., anything that is taking lots of time. Are there better ways to do what you're doing?

Also, when I ran your program, as posted, it generated a seg fault when tested with a small dictionary of a few words. It wouldn't show up with the large dictionary. I'll leave it to you to figure out. ;-)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

  • Ummm, well, I stand by my answer, but since then, I've discovered that, in addition, the servers really are having timing issues. It has been reported to staff. – Cliff B Jun 13 '16 at 22:37
  • As of a couple hours ago, the check50 servers have been restarted and appear to be running normally. – Cliff B Jun 14 '16 at 3:20
  • So I should implement tries to remove the time issue.Right? – Salil Jain Jun 14 '16 at 4:46
  • You could, if you wanted to, or you could just use a different hash method on the words to get more than 26 lists. – Cliff B Jun 14 '16 at 4:59
  • Okay Thanks, I will try. – Salil Jain Jun 14 '16 at 5:26
1

Its a problem many are facing for now. I also can't get pset6 checked by check50. Also it hasn't been graded for over 1 week. The problem is on the server side, not with your code. Wait for some more days or even keep checking with check50 in week days, maybe the servers will be less busy then. Meanwhile start the new week and submit your code if you feel like it's correct. You can always edit the code and resubmit it in case you get low grades for that. It'll hopefully work in the next few days :-).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .