albear
Apr 3, 2008, 05:25 PM
I have 2 files, one reads characters 1 coloumn of 11 strings,and the other reads integers a 100 numbers long(was in a 10 by 10 table but it didn't seem to like that), and is supposed to print both out togeather in a table 11 by 11, but for some reason it only prints the top row which consists of the 11 strings. If anybody could suggest where I have slipped up or am missing something, I would greatly apreciate it, thanks in advance.
int main ()
{
FILE* fin;
int count = 0;
int rowcount = 0;
int colcount = 0;
char placeNames[11][11];
int num = 0;
int myArray [11][11];
fin = fopen("Array.txt", "r");
if(fin==NULL)
{
printf("\n an error has occured please start again\n"); //error message
return -1;
}
count = 0;
do
{
fscanf(fin,"%s",&(placeNames[count++]));
} while (!feof(fin));
fclose(fin);
fin = fopen("Distances.txt", "r");
if(fin==NULL)
{
printf("\n an error has occured please start again\n"); //error message
return -1;
}
rowcount = 0;
do
{
colcount = 0;
do
{
if(feof(fin))
{
printf("\nError end of file reached");
}
int check = fscanf(fin,"%d",&(myArray[rowcount][colcount]));
if(check!=1)
{
printf("\n an error has occured please start again\n"); //error message
}
colcount++;
} while (colcount<11);
rowcount++;
} while (rowcount<11);
fclose(fin);
Table(placeNames,myArray);
Menu(placeNames,myArray);
return 0;
}
void Table(char placeNames[11][11],int myArray[11][11])
{
int row;
int col;
printf("\n\n My Distance Array \n\n");
for(col=0;col<11;col++)
{
printf("%5s",placeNames[col]);
}
for(row=0;row<11;row++)
{
printf("%10s",placeNames[row]);
for(col=0;col<11;col++)
{
printf(" %5s",myArray[row][col]);
}
printf("\n");
}
printf("\n\n");
return;
}
int main ()
{
FILE* fin;
int count = 0;
int rowcount = 0;
int colcount = 0;
char placeNames[11][11];
int num = 0;
int myArray [11][11];
fin = fopen("Array.txt", "r");
if(fin==NULL)
{
printf("\n an error has occured please start again\n"); //error message
return -1;
}
count = 0;
do
{
fscanf(fin,"%s",&(placeNames[count++]));
} while (!feof(fin));
fclose(fin);
fin = fopen("Distances.txt", "r");
if(fin==NULL)
{
printf("\n an error has occured please start again\n"); //error message
return -1;
}
rowcount = 0;
do
{
colcount = 0;
do
{
if(feof(fin))
{
printf("\nError end of file reached");
}
int check = fscanf(fin,"%d",&(myArray[rowcount][colcount]));
if(check!=1)
{
printf("\n an error has occured please start again\n"); //error message
}
colcount++;
} while (colcount<11);
rowcount++;
} while (rowcount<11);
fclose(fin);
Table(placeNames,myArray);
Menu(placeNames,myArray);
return 0;
}
void Table(char placeNames[11][11],int myArray[11][11])
{
int row;
int col;
printf("\n\n My Distance Array \n\n");
for(col=0;col<11;col++)
{
printf("%5s",placeNames[col]);
}
for(row=0;row<11;row++)
{
printf("%10s",placeNames[row]);
for(col=0;col<11;col++)
{
printf(" %5s",myArray[row][col]);
}
printf("\n");
}
printf("\n\n");
return;
}