Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.75 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 Server
  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.   struct Server;
  32.   int i;
  33.   int fda;      // to read from client
  34.   int fdb;      // to write to client
  35.  
  36.   /* Create the fifos and open them  */
  37.   if ((mkfifo("FIFO1",0666)<0 && errno != EEXIST))
  38.         {
  39.         perror("cant create FIFO1");
  40.         exit(-1);
  41.         }
  42.  
  43.    if ((mkfifo("FIFO2",0666)<0 && errno != EEXIST))
  44.         {
  45.         perror("cant create FIFO2");
  46.         exit(-1);
  47.         }
  48.  
  49.   if((fda=open("FIFO1", O_RDONLY))<0)
  50.      printf("cant open fifo to write");
  51.  
  52.   if((fdb=open("FIFO2", O_WRONLY))<0)
  53.      printf("cant open fifo to read");
  54.  
  55.   read(fda, &inst, sizeof(inst)); //read the struct from client
  56.  
  57.  
  58.   for( i = 0; i<6; i++) //for loop to write the first string from charbuff array to outchar array
  59.   {
  60.     inst.outchar1[i] = inst.charbuff1[i];
  61.     inst.outchar1[6] = 0;
  62.   }
  63.   printf("\nServer: first string is: %s", inst.outchar1);
  64.  
  65.   inst.l = 0;
  66.  
  67.   for( i = 0; i<6; i++) //for loop to check for non-lowercase characters
  68.   {
  69.   if(inst.outchar1[i] < 'a' && inst.outchar1[i] > 'z') //if a character isn't lowercase, set l to 9
  70.   {
  71.     inst.l = 9;
  72.     break;
  73.   }
  74.   else if(inst.outchar1[i] = 'a' || 'e' || 'i' || 'o' || 'u') //if a character is a vowel, increment l by 1
  75.   {
  76.     inst.l++;
  77.   }
  78.   else //if a character is a lowercase consonant, do nothing
  79.   {
  80.     inst.l;
  81.   }
  82.   }
  83.   printf("\nServer: Checked for uppercase letters");
  84.  
  85.   if(inst.l = 9) //if an invalid character was encountered
  86.   {
  87.     printf("\nServer: There are uppercase letters");
  88.   }
  89.   else //if no invalid character was encountered
  90.   {
  91.     printf("\nServer: There are no uppercase letters");
  92.     printf("\nServer: The humber of vowels are: %d", inst.l);
  93.   }
  94.  
  95.   for( i = 0; i<6; i++) //for loop to write the second string from charbuff array to outchar array
  96.   {
  97.     inst.outchar2[i] = inst.charbuff2[i];
  98.     inst.outchar2[6] = 0;
  99.   }
  100.   printf("\nServer: second string is: %s", inst.outchar2);
  101.  
  102.   inst.m = 0;
  103.  
  104.   for( i = 0; i<6; i++) //for loop to check for non-lowercase characters
  105.   {
  106.   if(inst.outchar1[i] < 'a' && inst.outchar1[i] > 'z') //if a character isn't lowercase, set m to 9
  107.   {
  108.     inst.m = 9;
  109.     break;
  110.   }
  111.   else if(inst.outchar2[i] = 'a' || 'e' || 'i' || 'o' || 'u') //if a character is a vowel, increment m by 1
  112.   {
  113.     inst.m++;
  114.   }
  115.   else //if a character is a lowercase consonant, do nothing
  116.   {
  117.     inst.m;
  118.   }
  119.   }
  120.   printf("\nServer: Checked for uppercase letters");
  121.  
  122.   if(inst.m = 9) //if an invalid character was encountered
  123.   {
  124.     printf("\nServer: There are uppercase letters");
  125.   }
  126.   else //if no invalid character was encountered
  127.   {
  128.     printf("\nServer: There are no uppercase letters");
  129.     printf("\nServer: The humber of vowels are: %d", inst.m);
  130.   }
  131.  
  132.   for( i = 0; i<6; i++) //for loop to write the third string from charbuff array to outchar array
  133.   {
  134.     inst.outchar3[i] = inst.charbuff3[i];
  135.     inst.outchar3[6] = 0;
  136.   }
  137.   printf("\nServer: third string is: %s", inst.outchar3);
  138.  
  139.   inst.n = 0;
  140.  
  141.   for( i = 0; i<6; i++) //for loop to check for non-lowercase characters
  142.   {
  143.   if(inst.outchar1[i] < 'a' && inst.outchar1[i] > 'z') //if a character isn't lowercase, set n to 9
  144.   {
  145.     inst.n = 9;
  146.     break;
  147.   }
  148.   else if(inst.outchar3[i] = 'a' || 'e' || 'i' || 'o' || 'u') //if a character is a vowel, increment n by 1
  149.   {
  150.     inst.n++;
  151.   }
  152.   else
  153.   {
  154.     inst.n; //if a character is a lowercase consonant, do nothing
  155.   }
  156.   }
  157.   printf("\nServer: Checked for uppercase letters");
  158.  
  159.   if(inst.n = 9) //if an invalid character was encountered
  160.   {
  161.     printf("\nServer: There are uppercase letters");
  162.   }
  163.   else //if no invalid character was encountered
  164.   {
  165.     printf("\nServer: There are no uppercase letters");
  166.     printf("\nServer: The humber of vowels are: %d", inst.n);
  167.   }
  168.   write(fdb, &inst, sizeof(inst));
  169.   printf("\nServer: This says I am ready to close.\n ");
  170.  
  171.   close(fda);
  172.   close(fdb);
  173.   unlink("FIFO1");
  174.   unlink("FIFO2");
  175.  
  176.         return 0;
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement