Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1.  
  2. #include <ctype.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <stdio.h>
  6. #include "source.h"
  7.  
  8. int read_lines(char *filename, char ***array, int size) {
  9. FILE* file = fopen(filename, "r");
  10. if (file == NULL) {
  11. return -1;
  12. }
  13. size_t len = 0;
  14. ssize_t nread;
  15.  
  16. int lines = 0;
  17. char* line = (char*) malloc(sizeof (file));
  18.  
  19. array = (char**) malloc((size) * sizeof (char**));
  20. while ((nread = getline(&line, &len, file)) != -1) {
  21.  
  22. array = realloc(array, (size + 1) * sizeof (char*));
  23. array[lines] = line;
  24.  
  25. size = size + 1;
  26. lines++;
  27. }
  28. array = realloc(array, (size + 1) * sizeof (char*));
  29. array[lines] = NULL;
  30. return lines;
  31. }
  32.  
  33. int shortest_string(char **array, int len) {
  34. return -1;
  35.  
  36. }
  37.  
  38. int find_lexi_first(char **array, int len) {
  39. return -1;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement