All pastes #1821 Raw Edit

Anonymous

public c v1 · immutable
#1821 ·published 2004-10-31 18:20 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>void fill(char des[20][40], int x, int y, char c){/* check if we are in bounds */        if (x < 0) return;        if (x > 19) return;        if (y < 0) return;        if (y > 39) return;/* if current position is a space, fill it in with <char> */        if(des[x][y]==' ') des[x][y]=c;/* recursively check around the current position for more white space to fill, until we reach non-space chars all around */        if(des[x][y-1]==' ') fill(des,x,y-1,c);        if(des[x-1][y]==' ') fill(des,x-1,y,c);        if(des[x][y+1]==' ') fill(des,x,y+1,c);        if(des[x+1][y]==' ') fill(des,x+1,y,c);}int main(void){        int line,column,i,j;        char charsel;        char drawing[20][40];        FILE *filein=NULL,*fileout=NULL;/* open files */        filein=fopen("in","rt");        fileout=fopen("out","wt");/* read the array from file ( array represents and ascii drawing of a house basically */        for(i=0;i<20;i++)        {                for(j=0;j<40;j++)                fscanf(filein,"%c",&drawing[i][j]);        }/* read coordinate at which we want to start filling in */        printf("Insert line (0-19) and column (0-39) number for the start position\n");        scanf("%d", &line);        scanf("%d", &column);        getchar();/* read character we are filling in with */        printf("Insert the fill character (must not be an empty space)\n");        scanf("%c",&charsel);/* run recursive function */        fill(drawing,line,column,charsel);/* print array back to output file */        for(i=0;i<20;i++)        {                for(j=0;j<40;j++)                fprintf(fileout, "%c", drawing[i][j]);        };        printf("Result has been spewed to file named 'out'");/* close shit up */        fclose(filein);        fclose(fileout);        getchar();        return 0;}