#include #include char buf[100]; void* logger(void* file){ FILE* fp; if((fp=fopen(file, "w"))==NULL) return; while(strcmp(buf, "end\n")){ fprintf(fp, buf); usleep(100000); // 0.1 sec } fclose(fp); } void* reader(void* x){ while(fgets(buf, 100, stdin)!=NULL && strcmp(buf, "end\n")){ ; } } main(){ pthread_t thre1, thre2; strcpy(buf, "not read\n"); pthread_create(&thre1, NULL, logger, "log.txt"); pthread_create(&thre2, NULL, reader, NULL); pthread_join(thre1, NULL); pthread_join(thre2, NULL); }