Note that there are some explanatory texts on larger screens.

plurals
  1. POI'm getting a really odd timing error, where something is executing before I believe it should
    primarykey
    data
    text
    <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;ctype.h&gt; #include &lt;string.h&gt; #include &lt;unistd.h&gt; #include &lt;errno.h&gt; int c, n, E, b, s, v, t, opt, valid = 0; char current = '\0'; char previous = '\0'; FILE *fp; /* -n numbers lines * -E appends a dollar sign to line ends * -b numbers only non-blank lines * -s squeezes multiple blank lines down to 1 * -v displays control chars, excluding tab * -t includes tab in the above * -e is the same as -E and -v */ int setFlags(int argc, char *argv[]) { int op; while ((op = getopt(argc, argv, "nEbsvte")) != -1) { switch (op) { case 'n': { n = 1; break; } case 'E': { E = 1; break; } case 'b': { b = 1; break; } case 's': { s = 1; break; } case 'v': { v = 1; break; } case 't': { t = 1; break; } case 'e': { E = 1; v = 1; break; } case '?': { //fprintf(stderr, "Option `-%c` is not valid.\n", optopt); return EXIT_FAILURE; } default: { abort(); } } } opt = optind; if(n == 1) { b = 0; } return EXIT_SUCCESS; } int checkFile(char *path) { if (access(path, R_OK) == 0) { return EXIT_SUCCESS; } else { fprintf(stderr, "cat: %s: %s\n", argv[i], strerror(errno)); errno = 0; return EXIT_FAILURE; } } int doPrint(char *path) { if (strcmp(path, "stdin") == 0) { fp = stdin; } else { if (checkFile(path) == 1) { return EXIT_FAILURE; } else { fp = fopen(path, "r"); } } while ((c = fgetc(fp)) != EOF) { putchar(c); } fclose(fp); return EXIT_SUCCESS; } int main (int argc, char *argv[]) { if (setFlags(argc, argv) == 1) { fprintf(stderr, "The program has terminated with an error.\n" "An invalid option was specified.\n"); return EXIT_FAILURE; } else { if ((argc - opt) == 0) { doPrint("stdin"); } else { for(int i = opt; i &lt; argc; i++) { doPrint(argv[i]); } } } } </code></pre> <p>I'm getting a really crazy bug, where my program outputs the error line in checkFile, before it finishes writing the contents of the file (always one chat before the end).</p> <p>It's driving me insane, and no matter where I move that piece of code, it doesn't work as intended.</p> <p>I'm sure the answer is probably trivial, but it has me stumped. I'd even thrown in sleeps and various other things just before output finished, and it would throw the error, THEN sleep, THEN print the final character.</p> <p>Any help?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload