All pastes #31643 Raw Edit

Mine

public c v1 · immutable
#31643 ·published 2005-11-29 02:27 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>#include <string.h>int main(int argc, char **argv){     char *line;     FILE *input;     char **buffer;     int lines, i;     if (argv[1]) {	  input = fopen(argv[1], "r");	  if (!input)	       exit(1);     } else {	  input = stdin;     }     line = calloc(81, sizeof(char));     lines = 0;     buffer = calloc(1, sizeof(char *));     while (fgets(line, 81, input)) {	  buffer[lines] = calloc(81, sizeof(char));	  strncpy(buffer[lines], line, 80);	  printf("Got and copied line %s\n", buffer[lines]);	  if (!realloc(buffer, sizeof(char *) * ++lines)) {	       perror("realloc error");	       exit(1);	  }     }     printf("Regurgitating...\n");     for (i = 0; i < lines; i++)	  printf("%s\n", buffer[i]);     return 0;}