#include <fstream>
#include <iostream>
#include <string>

// Starter: print the first line of a text file.
// Input: path names the file; standard output is writable.
// Output: 0 for a printed line, 1 for open failure, 2 for no readable line.
// Side effects: reads the file and writes the line plus a newline to standard output.
int print_first_line(const char* path) {
    std::ifstream input{path};
    if (!input) {
        return 1;
    }

    // TODO: Read until the first nonempty line, using getline and line.empty().
    // Keep whitespace significant. Return 2 if no nonempty line is extracted.
    // Let the local objects clean up; do not add close, free, new, or delete.
    std::string line;
    if (!std::getline(input, line)) {
        return 2;
    }

    std::cout << line << '\n';
    return 0;
}

int main(int argc, char* argv[]) {
    if (argc != 2) {
        std::cerr << "Usage: first-line FILE\n";
        return 64;
    }

    return print_first_line(argv[1]);
}
