Advertisement
Guest User

Untitled

a guest
Oct 16th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <fcntl.h>
  4. #include <sys/stat.h>
  5. #include <sys/ioctl.h>
  6. #include <string.h>
  7. #include <unistd.h>
  8.  
  9. int main (int argc, char* argv[]) {
  10.  
  11.     char num[2];
  12.  
  13.     printf("Insert a terminal number to output to [0-n]\n");
  14.     fgets(num, 2, stdin);
  15.  
  16.     char terminal[10] = "/dev/pts/";
  17.     strcat(terminal, num);
  18.  
  19.     int fd = open(terminal, O_RDWR);
  20.  
  21.     char input[1024];  
  22.    
  23.     printf("Enter some text to output to the specified terminal. When done key q to quit.\n");
  24.  
  25.     // Loop until user enters q and print all text to the specified terminal.
  26.     while (1) {
  27.  
  28.         if (input[0] == 'q') {
  29.             break;
  30.         }
  31.  
  32.         fgets(input, 1024, stdin);
  33.         write(fd, input, strlen(input));
  34.     }  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement