这是作业!
目前我正在做一个工作,我需要使用读调用从文件中读取字符,然后一次将字符写到屏幕上....好的在那里没有问题,但是每行之后我需要增加一个行计数器每隔20行,我需要暂停输出,直到用户按下空格为止
char buffer[1];
int n_char = 0;
//read (fileDesc, buffer, 5);
while( (n_char=read(fileDesc, buffer, 1))!=0)
{
if (buffer[1] == '\n')
{
//this is not incementing?
lineCount++;
}
if (lineCount % 20 == 0)
{
//wait for a space to be pressed
//for the time being sleep to make sure im counting lines correctly
sleep(5);
}
n_char=write(1,buffer,n_char);
}
目前我有一个问题,弄清楚为什么我不能检测换行符,任何帮助将不胜感激!
该buffer
声明
char buffer[1];
这意味着一个字符,但是要访问第一个字符,您必须说
if (buffer[0] == '\n')
数组索引从开始0
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句