Skip to content
Snippets Groups Projects
Select Git revision
  • c37e66a59e3e598bbd8ab7dabe4da44c8336cd4c
  • main default
2 results

dshlib.h

Blame
  • 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);
    }