Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.78 KB | None | 0 0
  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include <unistd.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <errno.h>
  8. #include <fcntl.h>
  9.  
  10. struct Client
  11. {
  12.   int l;             // stores number of vowels
  13.   int m;             // stores number of vowels
  14.   int n;             // stores number of vowels  
  15.   char charbuff1[7]; // buffer holds a character
  16.   char outchar1[8];  // server puts string here
  17.   char charbuff2[7]; // buffer holds a character
  18.   char outchar2[8];  // server puts string here
  19.   char charbuff3[7]; // buffer holds a character
  20.   char outchar3[8];  // server puts string here
  21. }
  22. inst;
  23. main (void)
  24. {
  25.   memset(inst.charbuff1,0,7);
  26.   memset(inst.outchar1,0,8);
  27.   memset(inst.charbuff2,0,7);
  28.   memset(inst.outchar2,0,8);
  29.   memset(inst.charbuff3,0,7);
  30.   memset(inst.outchar3,0,8);
  31.   int fda; // to write to server
  32.   int fdb; // to read response from server
  33.   struct Client;
  34.   int i;
  35.  
  36.   if((fda=open("FIFO1", O_WRONLY))<0) //open fifo to write to server
  37.      printf("cant open fifo to write");
  38.  
  39.   if((fdb=open("FIFO2", O_RDONLY))<0) //open fifo to read from server
  40.      printf("cant open fifo to read");
  41.  
  42.   printf("Client: Please enter up to 6 lowercase characters: ");
  43.   fgets(inst.charbuff1, 7, stdin);
  44.   fflush(stdin);
  45.   printf("Client: Please enter up to 6 lowercase characters: ");
  46.   fgets(inst.charbuff2, 7, stdin);
  47.   fflush(stdin);
  48.   printf("Client: Please enter up to 6 lowercase characters: ");
  49.   fgets(inst.charbuff3, 7, stdin);
  50.   fflush(stdin);
  51.   write(fda, &inst, sizeof(inst)); //write results to the struct
  52.  
  53.   printf("\nClient: Got the characters sent, now waiting for response ");
  54.   read(fdb, &inst, sizeof(inst)); //read results from server struct
  55.   printf("\nClient: received from server %s", inst.outchar1);
  56.   printf("\nClient: Was this a valid string? ");
  57.   if(inst.l = 9) //check if first string had an invalid character
  58.   {
  59.     printf("No");
  60.   }
  61.   else
  62.   {
  63.     printf("Yes");
  64.     printf("\nClient: The number of vowels in the string is: %d", inst.l);
  65.   }
  66.   printf("\nClient: The number of vowels in the string is: %d", inst.l);
  67.  
  68.   printf("\nClient: received from server %s", inst.outchar2);
  69.   printf("\nClient: Was this a valid string? ");
  70.   if(inst.m = 9) //check if second string had an invalid character
  71.   {
  72.     printf("No");
  73.   }
  74.   else
  75.   {
  76.     printf("Yes");
  77.     printf("\nClient: The number of vowels in the string is: %d", inst.m);
  78.   }
  79.   printf("\nClient: received from server %s", inst.outchar3);
  80.   printf("\nClient: Was this a valid string? ");
  81.   if(inst.n = 9) //check if third string had an invalid character
  82.   {
  83.     printf("No");
  84.   }
  85.   else
  86.   {
  87.     printf("Yes");
  88.     printf("\nClient: The number of vowels in the string is: %d", inst.n);
  89.   }
  90.  
  91.   close(fda);
  92.   close(fdb);
  93.  
  94.   printf ("\nall done!\n");
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement