Gets input from fd file descriptor and returns a single string regardless of the input size from the fd.
The string ends when there is a newline.
int find_network_newline(const char *buf, int n) {

    //loop through n characters
    for(int i = 0;i<n;i++){

        if(buf[i] == '\n'){
            return i+1;
        }
    }
    return -1;
}


/*
* returns a pointer to a string of the client's (from this fd) entire input. (up to \r\n).
*/
char *read_input(int fd){
     
     int size = 2;

     int nbytes;
     // Receive messages
     char *buf = malloc(size);
     int inbuf = 0;           // How many bytes currently in buffer?
     int room = size;  // How many bytes remaining in buffer?
     char *after = buf;       // Pointer to position after the data in buf
     int where; 

     while ((nbytes = read(fd, after, room)) > 0) {
          //add the amount of bytes just read.
          inbuf += nbytes;
          printf("%d, %c\n", inbuf, buf[inbuf-1]);
          //Determine if we have gained a full line.
          if ((where = find_network_newline(buf, inbuf)) > 0) {
               // where is now the index into buf immediately after 
               // the first network newline
               //now we must terminate the buf.
               buf[where-1] = '\0';
               printf("HELLO %s\n", buf);
               return NULL;

          }
          // Step 5: update after and room, in preparation for the next read.
          after = &buf[inbuf]; //inbuf+1 not needed because inbuf is size not index**
          room = size-inbuf;
          printf("%d \n", room);
          //double buf size*
          //we must do dynamic allocation within this function for that to work
          //dont forget to free the old memory
          //we will use memset
          if(room <= 0){
               size = 2*size;
               buf = realloc(buf, size);
               room = size - inbuf;
          }

     }
     printf("oops, %s", buf);
     //no end of line??
     return NULL;

}