如何用多线程(一个线程不断写文件A,另一个线程不断从文件A读入写入另一文件B)!
现在,,两个函数我已写好,,请问怎么用多线程来实现!
/////////////////////
DWORD WINAPI fun1(void *)
{
FILE *fp;
char ch;
CRITICAL_SECTION cm_fp;
if ((fp=fopen("d:\\1.txt","a+"))==NULL)
{
printf("cannot open file\n");
exit(1);
}
ch=getchar();
while (ch!='#')
{
while (ch!='\n')
{
fputc(ch,fp);
fflush(fp);
ch=getchar();
}
ch=getchar();
}
fclose(fp);
}
DWORD WINAPI fun2(void *)
{
FILE *in,*out;
char buf[10];
CRITICAL_SECTION cm_fp;
if((in=fopen("d:\\1.txt","rb"))==NULL)
{
printf("cannot open infile\n");
exit(0);
}
if((out=fopen("d:\\2.txt","a+"))==NULL)
{
printf("cannot open outfile\n");
exit(0);
}
while (!feof(in))
{
fputs(fgets(buf,10,in),out);
fflush(out);
}
fclose(in);
fclose(out);
}