Facebook
From Tinct Crocodile, 5 Years ago, written in Plain Text.
This paste is a reply to Re: Untitled from Sweet Motmot - view diff
Embed
Download Paste or View Raw
Hits: 336
  1.  
  2.  
  3. #include <stdio.h>
  4. #include <limits.h>
  5. #include <string.h>
  6. #include <ctype.h>        
  7.  
  8. int main() {
  9.         FILE *stream;
  10.         char buffer[LINE_MAX];
  11.         int run;
  12.  
  13.         int empty(char*);
  14.         if ((stream = fopen("channel", "r+"))) run = 1;
  15.         else
  16.         {
  17.                 run = 0;
  18.                 perror("!.!..blad otwarcia lacza..!.!");
  19.         }
  20.  
  21.         while (run) {
  22.                 bzero((void*)buffer,LINE_MAX);
  23.                 fgets(buffer,LINE_MAX,stdin);
  24.                 if (!empty(buffer))
  25.                 {
  26.                         fprintf(stream, "%s\n", buffer);
  27.                         fflush(stream);
  28.                 }
  29.                 else {
  30.                         fclose(stream);
  31.                         break;
  32.                 }
  33.                 fgets(buffer,LINE_MAX,stream);
  34.                 if (!empty(buffer))
  35.                 {
  36.                        fprintf(stdout, "%s\n",buffer );
  37.                        fflush(stream);
  38.                 }
  39.  
  40.         }
  41.         return 0;
  42. }
  43.  
  44. int empty(char * string) {
  45.         while (*string) {
  46.                 if (isalnum(*string++))
  47.                 {
  48.                         return 0;
  49.                 }
  50.         }
  51.         return 1;
  52. }