Advertisement
rakoczyn

Prime Numbers - CLIENT

Oct 22nd, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <limits.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <unistd.h>
  6. #include <sys/wait.h>
  7. int main( void )
  8. {
  9.     FILE *stream;
  10.     char buffer[LINE_MAX];
  11.     int run;
  12.     int empty( char* );
  13.     if( (stream = fopen( "channel","r+" ) ) )
  14.         {
  15.             run=1;
  16.         }
  17.     else
  18.         {
  19.             run=0;
  20.             perror( "!.!..błąd otwarcia łącza..!.!" );
  21.         }
  22.  
  23.     printf("%s\n", "Ile liczb pierwszych chcesz?");
  24.     int N;
  25.     scanf("%d",&N);
  26.     printf("%s %d %s\n", "Wybrales ",N," liczb losowych.");
  27.     fprintf(stream, "%d\n", N);
  28.  
  29.    
  30.     fflush(stream);
  31.     sleep(1);
  32.     while( run )
  33.     {
  34.        
  35.        
  36.         if( fgets( buffer,256,stream ) )
  37.         {
  38.             //int* pierwsze[N];
  39.             //sscanf(buffer,"%d\n",);
  40.  
  41.             printf("%s\t%s\n",":: FROM SERVER:",buffer);
  42.        
  43.              
  44.             fflush( stream );
  45.         }
  46.        
  47.     }
  48.  
  49.     return 0;
  50. }
  51.  
  52. int empty( char * string )
  53. {
  54.     while( *string )
  55.         {
  56.             if( isalnum(*string++) )
  57.                 {
  58.                     return 0;
  59.                 }
  60.         }
  61.     return 1;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement