are there two things written to the pipe?


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>                              // remove errno import
#define MAXLINE 256

#define SUCCESS "Password verified\n"
#define INVALID "Invalid password\n"
#define NO_USER "No such user\n"

int main(void) {
  char user_id[MAXLINE];
  char password[MAXLINE];

  /* The user will type in a user name on one line followed by a password
     on the next.
     DO NOT add any prompts.  The only output of this program will be one
         of the messages defined above.
     Please read the comments in validate carefully
   */

  if(fgets(user_id, MAXLINE, stdin) == NULL) {
      perror("fgets");
      exit(1);
  }
  if(fgets(password, MAXLINE, stdin) == NULL) {
      perror("fgets");
      exit(1);
  }
//user_id[strcspn(user_id, "\n\r")] = '\0';
//password[strcspn(password, "\n\r")] = '\0';
printf("%s %s\n", user_id, password);

  // TODO
  int fd[2];

  if (pipe(fd) == -1){
        perror("pipe\n");
  }

  int n = fork();

  // parent process
  if (n > 0){

        close(fd[0]);

        // write username to pipe
        if (write(fd[1], user_id, MAXLINE/2) == -1){
                perror("write to pipe\n");
        }
        // write password to pipe
        if (write(fd[1], password, MAXLINE/2) == -1){
                perror("write to pipe\n");
        }
        close(fd[1]);
printf("made it to wait\n");
        int status;
        if (wait(&status) == -1){
                perror("wait\n");
        }

        // child terminated
        if (WIFEXITED(status)){
                int child_status = WEXITSTATUS(status);

                if (child_status == 0){
                        printf("%s", SUCCESS);
                }
                else if (child_status == 2){
                    printf("%s", INVALID);
                }
                else if (child_status == 3){
                        printf("%s", NO_USER);
                }
                // else: error

        }

  }
  // child process
  else if (n == 0) {

          // close the write file descriptor
      close(fd[1]);
printf("made it to child process\n");
          char *username_password[] = {"./validate", NULL};

          dup2(fd[0], fileno(stdin));

          execl("./validate", "validate", NULL);
          close(fd[0]);

          perror("exec\n");
          exit(1);

  }

  else {
        perror("fork\n");
        exit(1);
  }

  return 0;
}
