gpt4 book ai didi

c - 从文件中读取并存储到缓冲区

转载 作者:行者123 更新时间:2023-11-30 15:38:04 24 4
gpt4 key购买 nike

有人可以告诉我,在生产者消费者问题中,如何从文件中读取一行并将其存储到大小为 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);

关于c - 从文件中读取并存储到缓冲区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21943896/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com