/* Draw a tree and store it in a file Emad Arasteh Original version without file handling by Weiwei Chen December 5 , 2019 */ #include #include void tree(int a, int b) { int i, j; FILE* f; f = fopen("tree.txt", "w"); if (!f) { printf("\nCouldn't open the file\n"); exit(1); } for(i = 0; i < a; i ++) { for(j = 0; j < a - i; j ++) { fprintf(f, " "); } for(j = 0; j < i * 2 + 1; j ++) { fprintf(f, "*"); } fprintf(f, "\n"); } for(i = 0; i < b; i ++) { for(j = 0; j < a - 1; j ++) { fprintf(f, " "); } fprintf(f, "+++\n"); } fclose(f); } int main() { printf("Drawing a tree in a tree.txt...\n"); tree(20, 6); return 0; }