C标准输入/输出线

时间:2017-10-02 17:46:07

标签: c input output standards

我是C的新手,我正在尝试编写一个读取标准输入并将其复制到标准输出的小程序。我们被赋予了readline和writeline的功能,我应该用它来完成这项任务。我一直有很多错误,但我不知道如何解释或修复它们,有人可以帮助我吗?

以下是我得到的错误:

lfcopy.c: In function ‘main’:
lfcopy.c:11: error: expected expression before ‘char’
lfcopy.c:11: error: too few arguments to function ‘readline’
lfcopy.c:12: error: expected expression before ‘const’
cc1: warnings being treated as errors
lfcopy.c:9: warning: unused variable ‘max’

这是我的文件lfcopy:

#include <stdio.h>
#include <string.h>
int readline(char line[], int max);
int writeline(const char line[]);

int main(){
   int c;
   int max = 100;


   while ((c = readline(char line[], max)) != 0)
      writeline(const char line[]);

   return 0;
}

/* readline: read a line from standard input, return its
 * length or 0
 * */
int readline(char line[], int max)
{
   if (fgets(line, max, stdin) == NULL)
      return 0;
   else
      return strlen(line);
}
/* writeline: write line to standard output, return number of chars
 * written */
int writeline(const char line[])
{
   fputs(line, stdout);
   return strlen(line);
}

0 个答案:

没有答案