/* * This program illustrates the idea that all Linux/Unix devices * can be treated as a file. */ #include int main(int argc, char* argv[]) { FILE *wp; /* file pointers for read/write */ FILE *rp; char buf[80]; /* string buffer of random length */ int count; /* some random integer value */ count = 10; wp = fopen("/dev/pts/0","w"); rp = fopen("/dev/pts/1","r+"); if (rp == NULL || wp == NULL) fprintf(stderr, "error\n"); fprintf(rp,"hello world, type something\n"); fscanf(rp,"%s",buf); fprintf(rp,"%s\n",buf); printf("%s\n",buf); fflush(rp); fprintf(rp,"%d", count); fscanf(rp,"%d",&count); fprintf(rp,"%d\n",count); printf("%d\n",count*2); printf("wait...\n"); scanf("%d", &count); fprintf(wp, "wrote to pts0 %d\n", count); return 0; }