0

From what I see, the library is not used in this CS50 sample code and yet, it's included:

#include <stdio.h>
//#include <unistd.h>

int main(int argc, char* argv[])
{
    if (argc != 2)
    {
        printf("Usage: %s [name of document]\n", argv[0]);
        return 1;
    }
    FILE* fp = fopen(argv[1], "r");
    if (fp == NULL)
    {
        printf("Could not open %s\n", argv[1]);
        return 1;
    }
    char output[256];

    for (int i = 1; fgets(output, 256, fp) != NULL; i++)
        printf("Line %02d: %s", i, output);

    fclose(fp);
    return 0;
}

CS50 VIDEO

I commented out the include line for unistd and the program runs fine. I couldn't find a man page for it, but I did find this.

I looked through the functions, and could not find one that is being used. I'm sure there's a reason it is included. What is that reason?

Thanks for any help.

0

I believe I found the answer, from this Quora link. It says that it is used for a number of constants, types, and functions, and that many of the header files you link to, link unistd.h anyways.

If anyone can explain it's inclusion a bit more (i.e: is some kind of standard, a good practice to follow?), it would be greatly appreciated.

You must log in to answer this question.

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