new to coding and working on my pset1. Program works great, but I get this EOF error. Thoughts? Here's my code

#include <stdio.h>
#include <cs50.h>

int main(void)
    // declares the variable n while not assigning a value to it. This allows it to be used in nested loops later in the script, rather than appearing in the do/while loop
    int n;

    // repeats this script until the conditions in the "while" section are met

        n = get_int("Height: ");
    while (n < 1 || n > 23);

    // the variable i detremines the number of rows

    for (int i = 0; i < (n); i++)
    // the variable j determines the number of spaces

        for (int j = 1; j < (n - i); j++)
            printf(" ");

        // the variable k determines the number of octothropes
        for (int k = (n - i); k < (n + 2); k++)

1 Answer 1


What is "this" EOF error? Please provide more context so we know what you are talking about. If it is a failing check50 test case, the link check50 provides can often tell more. If not, specify how the programme misbehaves. This is even better, as you try to understand what the programme should do. Some people build their solution around the test cases, and sure, it makes them pass, but does not have them learn.

The thing I see is that you reject 0, but 0 is a valid input, printing 0 lines. The problem specification asks for a "a non-negative integer no greater than 23", and 0 surely is non-negative and no greater than 23.

I assume the test case is an input of 0, and waiting for the programme to finish without printing a single line. But your programme waits for input, and gets terminated after a few seconds.

  • here's the comment from check50, :( handles a height of 0 correctly did not find EOF Nov 5, 2018 at 20:57
  • and here is the longer feedback from check50: did not find EOF Log running ./mario... sending input 0... checking for EOF... Nov 5, 2018 at 21:18
  • So it is the one I suspected. Have you tried fixing it then, by rejecting negative numbers only, not those less than 1?
    – Blauelf
    Nov 6, 2018 at 9:28
  • I think you need to write return 0; in the end of main function
    – Pavel
    Nov 6, 2018 at 16:08
  • The main function is the only function with an implicit return 0; at the end if you don't specify a return value. For all other functions, the return value would be undefined.
    – Blauelf
    Nov 6, 2018 at 16:12

You must log in to answer this question.

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