I'm trying to do this:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define MAX_SIZE 50
int main()
{
    char *s = malloc(sizeof(char)*MAX_SIZE);
    do{
      int r = read(STDIN_FILENO, s, MAX_SIZE);
      if(r==-1) printf("error ");
      else{
        write(STDERR_FILENO, s, MAX_SIZE);
      }
      while(getchar()!='\n');
    } while(strcmp(s,"end\n")!=0);
    free(s);
    return 0;
}
My question is: is fflush(stdin) in this case an undefined behavior? As I searched on internet, I readed that in a case fflush(stdin) is a defined behavior: By the standard C pass an input stream to fflush is an undefined behavior ... STDIN is an input stream (buffered) I think the undefined behavior is when the standard C doesn't specify which behavior must have a specific function in specific cases.
So it is an undefined behavior by following the standard C right?
So is in this case an undefined behavior?
 
     
    