yours is much neater cosmic_cow.. I've another problem.
I need the x coordinate to be between 0 and 19, and the
y coordinate to be between 10 and 19.[As stated in the condition]
I tried entering a coordinate of (5,5). This is supposed to yield
a value of 1. then it's supposed to go through the while loop again but it's not looping! Can someone tell me why? thanks!
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int x,y,i,j,A,invalid=1,rc;
FILE* fw = fopen("status.txt", "r");
FILE* fp = fopen("status.txt", "w");
/*Creating a text file which has 20 rows of 20 zeroes*/
for(i=0;i<20;i++)
{
for(j=0;j<20;j++)
fprintf(fp,"%d ", 0);
fprintf(fp,"\n");
}
fclose(fp);
while(invalid)
{
printf("Please enter the coordinate:\n");
scanf(" %d %d", &x,&y);
invalid=((x>0 && x<19) &&(y>10 && y<19))? 0: 1;
printf("The value of invalid the first time is %d\n", invalid);
A=20*y+x;
if(invalid=0)
{
/*Reading the status.txt file*/
for (i=0;i<=A;i++)
{
fscanf(fw, "%d ", &rc);
}
fclose(fw);
if (rc==1)
invalid=1;
else
invalid=0;
}
}
return 0;
}