Ask Experts Questions for FREE Help!
  Advanced
Register  |  Log in  
   Ask    
 Answer  
  Help  

Ask QuestionsprogressAnswer QuestionsprogressBuild ReputationprogressBecome an Expert
 
Free Answers in 3 Easy Steps

Register Now
3 Steps

At Ask Me Help Desk you can ask questions in any topic and have them answered for free by our experts. To ask questions or participate in answering them you must register for a free account. By registering you will be able to:
  • Get free answers from experts in any of our 300+ topics.
  • Accept money for answers that you provide.
  • Communicate privately with other members (PM).
  • See fewer ads.

Home > Computers & Technology > Programming > Compiled Languages > C   »   problems with reading from file

 
Question Tools Search this Question Display Modes
Question
 
 
#1  
Old Apr 3, 2008, 04:25 PM
albear's Avatar
albear
Senior Member
albear is offline
 
Join Date: Apr 2007
Location: strawberry fields
Posts: 685
albear See this member's comment history on his/her Profile page.
problems with reading from file

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 didnt 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;
}

Reply With Quote
 
     

Answers
 
 
Old Apr 4, 2008, 10:19 AM   #2  
albear
Senior Member
albear is offline
 
albear's Avatar
 
Join Date: Apr 2007
Location: strawberry fields
Posts: 685
albear See this member's comment history on his/her Profile page.
if any more information is needed please let me know
  Reply With Quote
 
     
 
 
Old Apr 4, 2008, 04:19 PM   #3  
albear
Senior Member
albear is offline
 
albear's Avatar
 
Join Date: Apr 2007
Location: strawberry fields
Posts: 685
albear See this member's comment history on his/her Profile page.
ive read that it could possibly be my 'feof' but im not sure why or if its true,
  Reply With Quote
 
     


Question Tools Search this Question
Search this Question:

Advanced Search
Display Modes

 
Similar Sponsors

Similar Questions
Question Asker Topic Answers Last Post
H4 Visa: 2007 Tax Filing Status - To file or Not to File iag Taxes 1 Mar 21, 2008 10:58 AM
File W-7 form without tax return and why to file as a resident alien? Ankita84 Taxes 1 Mar 1, 2008 08:53 AM
File as married & self-employed: live in NY and do biz in Florida. Where do I file? beli50 Taxes 1 Nov 27, 2007 05:19 PM
Reading from an .mpp file prabu_507 Other Software 0 Jun 20, 2007 11:28 PM
Outlook 2003 - checking data file 'Personal Folders' for problems DrJizzle Email 2 Sep 12, 2006 09:32 AM




Copyright ©2003 - 2007, Ask Me Help Desk.
All times are GMT -8. The time now is 05:09 PM.

Content Relevant URLs by vBSEO 3.0.0 RC6 © 2006, Crawlability, Inc.