小编ark*_*rka的帖子

C 中 Linux 特定 getline() 函数的意外行为

#include <stdio.h>
#include <stdlib.h>
#define MAXLEN 1024

void reverse(FILE *, FILE *);

int main(int argc, char ** argv)
{
  ...
  reverse(fptr, stdout);
  ...

  return 0;
}

void reverse(FILE * instream, FILE * outstream)
{
  char ** buf;
  char * lbuf;
  int counter, i;
  size_t slen;

  counter = 0;

  buf = malloc(MAXLEN * sizeof(char));
  if (buf == NULL)
  {
    fputs("malloc failed\n", stderr);
    exit(EXIT_FAILURE);
  }

  lbuf = NULL;
  while ((counter < MAXLEN) && (getline(&lbuf, &slen, instream) != -1))
  {
    buf[counter] = lbuf; …
Run Code Online (Sandbox Code Playgroud)

c glibc stdio

0
推荐指数
1
解决办法
124
查看次数

标签 统计

c ×1

glibc ×1

stdio ×1