Advertisement
rjcostales

fileutils.h

Feb 11th, 2021
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.41 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "fileutils.h"
  5.  
  6. typedef char *str;
  7.  
  8. int read(str strings[])
  9. {
  10.     int i;
  11.     char line[MAXLINE];
  12.  
  13.     for (i = 0; fgets(line, MAXLINE, stdin); i++) {
  14.         strings[i] = malloc(strlen(line) + 1);
  15.         strcpy(strings[i], line);
  16.     }
  17.     return i;
  18. }
  19.  
  20. void write(str strings[])
  21. {
  22.     for (int i = 0; strings[i] != NULL; i++)
  23.         fputs(strings[i], stdout);
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement