Skip to content

Commit

Permalink
Pass reverse test remzi-arpacidusseau#7
Browse files Browse the repository at this point in the history
  • Loading branch information
Ampretuzo committed May 2, 2021
1 parent 850428a commit 133c58d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 12 additions & 1 deletion initial-reverse/reverse.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,19 @@ void reverse_seekable(FILE *in, FILE *out, FILE *err) {
}
}


void reverse(FILE *in, FILE *out, FILE *err) {
fprintf(err, "TODO");
char *lines[10];
unsigned int num_lines = 0;
size_t line_len = 0;

while (getline(&lines[num_lines], &line_len, in) != -1) {
num_lines ++;
}

for (int i = 0; i < num_lines; i++) {
fprintf(out, lines[num_lines - i - 1]);
}
}


Expand Down
7 changes: 4 additions & 3 deletions initial-utilities/wgrep/wgrep.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ char *mystrstr(const char *haystack, const char *needle) {
}


void print_matches(FILE *input, char *searchterm) {
void wgrep(FILE *input, char *searchterm) {
char *line = NULL;
size_t len = 0;
bool read_successful = true;
Expand All @@ -47,7 +47,8 @@ void print_matches(FILE *input, char *searchterm) {
* stdin would be acquired. But what to feed to it to cause some
* errors?
*/
perror("print_matches");
read_successful = false;
perror("wgrep");
}

free(line);
Expand Down Expand Up @@ -88,7 +89,7 @@ int main(int argc, char* argv[]) {
return 1;
}

print_matches(file, searchterm);
wgrep(file, searchterm);

fclose(file);
}
Expand Down

0 comments on commit 133c58d

Please sign in to comment.