How to print to stderr in C

2 Answers

0 votes
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[]){

    if (argc != 2) {
        fprintf(stderr, "ERROR: No program arguments\n");
        exit(EXIT_FAILURE);
    }

    return(0);
}





/*
run:

ERROR: No program arguments

*/

 



answered May 4, 2021 by avibootz
0 votes
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[]){

    if (argc != 2) {
        fwrite("ERROR: No program arguments\n", 32, 1, stderr);
        exit(EXIT_FAILURE);
    }

    return(0);
}





/*
run:

ERROR: No program arguments

*/

 



answered May 4, 2021 by avibootz

Related questions

1 answer 212 views
2 answers 133 views
133 views asked Apr 10, 2021 by avibootz
...