Select Git revision
-
Ziheng Chen authoredZiheng Chen authored
dragon.c 751 B
#include <stdio.h>
#include <stdlib.h>
#include "dshlib.h"
// EXTRA CREDIT - print the drexel dragon from the readme.md
extern void print_dragon(){
// TODO implement
FILE *dragon = fopen("dragon.txt", "r");
if (dragon == NULL) {
return;
}
char *s = NULL;
size_t nbyte;
ssize_t nchar;
while (1) {
nchar = getline(&s, &nbyte, dragon);
if (nchar == -1) { // end of file reached
break;
}
if (nchar == 0) {
continue;
}
if (s == NULL) { // out of memory
exit(1);
}
if (s[nchar - 1] == '\n') {
s[nchar - 1] = '\0'; // remove newline
nchar--; // newline removed
}
printf("%s\n", s);
}
free(s);
fclose(dragon);
}