0

Please, I need your help. I have dependency issue with my code. This is check50 response on my code. I guess the problem is with my load function. After a few tweaks on the code to fix the dependency issue, the load function refused to load. I have spent much time on it but could not understand what the problem is. Below is a snippet of the code. Debug50 is of no use, as it just says "could not load dictionary/large". Do please, lend some advice.

int word_count = 0; 

bool load(const char *dictionary) {

inptr = fopen ("dictionary", "r+");

if (inptr == NULL)
{
    return false;
    printf ("Could not open dictionary\n");
    fclose(inptr);
}

 node* root = calloc(1, sizeof(node));
 node* pecker = root;

 while (!&feof)
{
    c = fgetc(inptr);

    if (c == '\n')
    {
        pecker -> is_word = true;
        pecker = root;
        index = 0;
    }
    if (isalpha(c))
    {
        tolower(c);
        index = (c - 'a');
    }

     while ((pecker -> branches[index]) == NULL) 
    {
        pecker = calloc (1, sizeof(node));
        pecker = pecker -> branches[index];
    }

    if (c == '\'')
    {
        index = 26;

        if (pecker -> branches[index] == NULL)
        {
        pecker = calloc (1, sizeof(node));
        pecker = pecker -> branches[index];
        }
        else if (pecker -> branches[index] != NULL)
        {
            pecker = pecker -> branches[index];
        }
    }

        FILE* outptr;

        outptr = fopen ("dictionary", "w+");

        if (outptr != NULL)
        {
            fclose (outptr);
        }
        else if (outptr == NULL)
        {
            fputc (c, outptr);
        }
         word_count++;

        if (&feof)
        {
        fclose(inptr);
        }
}

   return false;

}

1
  • With this now being a completely different question (your first was about check50 and that it won't find dictionary.c), you should have created a new question. Now my twice upvoted answer is no longer related to your question, which might confuse readers. – Blauelf Jan 24 '17 at 8:40
2

Your call to check50 might not include the right parameters, check the description on how to call it for that particular problem. check50 does not do the checks itself, but relies on a special server it uploads the files to.

For the upload to work properly, you need to be in the right directory, where your files are, those have to have the right name, and it's best to not change files you won't upload using the check50 tool. The checker will take your uploaded files, and try to build the software, and in the output you provided, it could not find dictionary.c, so you likely did not upload it, or otherwise messed up the check50 call.

1
  • I'm really sorry for the confusion and inconvenience I must I have caused. I'm not yet adept at these things. I'm still just learning the ropes. My problem is still there I'm hoping that someone can point out load couldn't load. Thanks. – doublestanding Jan 24 '17 at 8:58
1

One big problem comes here inptr = fopen ("dictionary", "r+");. "dictionary" (in quotes) is a string literal. The program is looking for a file in the working directory called dictionary. You need to open the file name that has been sent to the program in the variable named dictionary. The proper syntax would be inptr = fopen (dictionary, "r");. [IMO you should not use "r+" because you should never write to the input dictionary file.] That's probably what's causing debug50 to bail too. Assuming there is not a file name "dictionary", inptr is NULL, and load immediately returns false. Since your program doesn't run yet, it might be a bit premature to send it through check50.

This load function never returns true so speller will always give "could not load dictionary" message. Best to set a breakpoint in dictionary.c when using debug50.

This line while (!&feof) is meaningless, I can't even speculate why it even compiles. I suspect the while loop never executes (debug50!). Watch this short on File I/O, paying special attention around 7:30 why one shouldn't use feof in a while loop.

You have a lot a work ahead of you to have a successful pset5. You will need to put in a lot of debug50 time.

6
  • Thanks, @DinoCoderSaurus, I have implemented those changes, but nothing has changed, except loss of memory at line 81(which initially was not there], upon the fact that I freed &root and &branches[index]. About going to chck50, I did it out of exasperation, to know if I can get some diagnostic information from therein! – doublestanding Jan 23 '17 at 23:36
  • Another quick scan: when and where does the function return true? You should be able to use debug50. set a breakpoint at the beginning of load in dictionary.c and walk it through. (small dictionary might be easier to start with) – DinoCoderSaurus Jan 23 '17 at 23:41
  • clang -ggdb3 -O0 -Qunused-arguments -std=c11 -Wall -Werror -c -o speller.o speller.c clang -ggdb3 -O0 -Qunused-arguments -std=c11 -Wall -Werror -c -o dictionary.o dictionary.c clang -ggdb3 -O0 -Qunused-arguments -std=c11 -Wall -Werror -o speller speller.o dictionary.o ~ Usage: speller [dictionary] text: Can this be of any diagnostic value? – doublestanding Jan 24 '17 at 0:16
  • Can unused arguments make a function to fail, because, it seems Clang is claiming that there are unused arguments in the code. I thought unused arguments are redundant in a code. – doublestanding Jan 24 '17 at 0:19
  • clang is not claiming there are "unused arguments" in the code. The -Qunused-arguments switch suppresses compiler warnings about unused arguments in the clang command line, not arguments in the code. Answer emended. – DinoCoderSaurus Jan 24 '17 at 3:00

You must log in to answer this question.

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