sun4lower
3/16/2018 - 10:07 AM

stdin stdout and stderr in C

Test the stdin stdout and stderr in C.

#include <stdio.h>
/**
 * stdin
 * stdout
 * stderr
 * 
 * fprintf: write formatted ouput to a stream.
*/

int main()
{
  int a;
  // printf("please type the input value...");
  fprintf(stdout, "please type the input value...\n");
  fscanf(stdin, "%d", &a);
  if(a < 0) {
    //stderr
    fprintf(stderr, "the input must bigger than 0.\n");
    return 1;
  }
  return 0;
}