-1

I had a few questions in speller.c that I didn't fully understand. First, why does it include #undef getrusage if it never redefines it? Maybe i'm not fully understanding undef.

And also. for:

// ignore alphabetical strings too long to be words
if (index > LENGTH)
{
    // consume remainder of alphabetical string
    while ((c = fgetc(fp)) != EOF && isalpha(c));

    // prepare for new word
    index = 0;
}

Can you explain the Consume remainder of alphabetical string to me? Why doesn't the while loop do anything? What does it mean if the while loop statement just ends with a semi colon? What is it supposed to be doing?

Can you explain what const struct means? Is it the same as a struct but the values don't change?

Thanks!

1
  • This question is too broad and asks too many things. Narrow down your question to one subject at a time. – Luke Van In Jul 12 '16 at 9:30
3

An #undef could be used to deal with a macro that is previously defined elsewhere, such as in a header file. It's possible that there are conflicting references to the named macro. It might be a macro in one place and a function in another.

In this case, it was determined that whatever is being read is simply too long to be a word, so it is reading until it finds the next non-alpha, which will indicate it has ended and a new word is coming. By creating a while loop with just a semicolon, it is doing whatever is in the while loop setup, the read, but the while loop code block (the code that would be inside curly braces) is replaced with a seimcolon that means "do nothing while looping".

In a const struct, once the variable is declared and initialized, it cannot be changed. Here's a link with more explanation: https://stackoverflow.com/questions/4266914/how-does-a-const-struct-differ-from-a-struct

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

You must log in to answer this question.

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