0
任何人都可以告訴我,在生產者消費者問題中,如何從文件中讀取一行並將其存儲到大小爲10的緩衝區中?從文件中讀取並存入緩衝區
static char buf[10][256];
void *producer(void *var)
{
char line[256];
int i;
for(;;)
{
if(feof)
break;
for(i=0;i<10, i++)
buf = fgets(line,256, in); // what should be the correct coding here to read from file and store in buffer ?
if (pushInBuffer(&buf))
fprintf(stderr, "Error Consuming");
}
pthread_exit(0);
}
'fgets(buf [i],256,in);'This post may help you http://stackoverflow.com/questions/3501338/c-read-file-line-by-line – user376507