Hello,
I encountered a problem with my code. Its doesn't print correctly. Here my output
[img]
http://img413.imageshack.us/img413/8392/outputgsv1.jpg
[/img]
and here's my code
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define XMAX 65
#define YMAX 32
char screen[XMAX][YMAX];
void printScreen(void);
void fill(int, int, char*, int);
int main(int argc, char *argv[])
{ FILE *in;
int x, y;
char* a;
int ArraySize;
if (argc!= 5)
{ fprintf(stderr,"Usage:\n\t%s <65x32 text file> <x> <y> <sentences>\n",argv[0]);
exit(1);
}
in = fopen(argv[1],"r");
if (in == NULL)
{ perror("opening input file");
exit(1);
}
for (y=0; y<YMAX; y++)
{ for (x=0; x<XMAX; x++)
screen[x][y] = fgetc(in);
}
if (fclose(in))
{ perror("closing input file");
exit(1);
}
x = atoi(argv[2]);
y = atoi(argv[3]);
a = argv[4];
ArraySize = strlen(a);
while (a[ArraySize] ^ 0)
ArraySize++;
fill(x,y,a, ArraySize);
printScreen();
}
void printScreen (void)
{ int x,y;
for (y=0; y<YMAX; y++)
for (x=0; x<XMAX; x++)
if(screen[x][y]!= EOF)
putchar(screen[x][y]);
else
puts("\n");
}
void fill(int x, int y, char* a, int i)
{
if (screen[x][y] != ' ')
return;
screen[x][y] = *a;
fill(x+1,y,a++,i);
if(*a == 0)
a-=i;
fill(x,y-1,a,i);
fill(x-1,y,a,i);
fill(x,y+1,a,i);
Suppose if I choose ABC as my sentences it should print ABC repetedly but mine got the output kind of mixed up. May I know where's my problem in my code? Ok. Thanks