Ask Experts Questions for FREE Help !
Ask
    albear's Avatar
    albear Posts: 1,594, Reputation: 222
    Ultra Member
     
    #1

    Apr 3, 2008, 05:25 PM
    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 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;
    }
    albear's Avatar
    albear Posts: 1,594, Reputation: 222
    Ultra Member
     
    #2

    Apr 4, 2008, 11:19 AM
    If any more information is needed please let me know
    albear's Avatar
    albear Posts: 1,594, Reputation: 222
    Ultra Member
     
    #3

    Apr 4, 2008, 05:19 PM
    I've read that it could possibly be my 'feof' but I'm not sure why or if its true,

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search


Check out some similar questions!

H4 Visa: 2007 Tax Filing Status - To file or Not to File [ 1 Answers ]

Hi, I am on H4 from 2006. Filed tax for 2006 using ITN with my spouse(H1) as Joint Return. My spouse wants to do Married filing Separately FOR 2007. My question is for 2007, 1) Do I need to file a separate return in spite of lack of income(H4) ? 2) Or do I just leave it as such and not file at...

File W-7 form without tax return and why to file as a resident alien? [ 1 Answers ]

I came to USA in August 2004 on F1 Visa. I graduated and change status to H1b visa from October 2007. Now, I got married and my hasband came to USA on January 2008 on H4 visa. I have my brothers whom I can claim as they have green card and not earning anything. I will have to wait till May 2008...

File as married & self-employed: live in NY and do biz in Florida. Where do I file? [ 1 Answers ]

I moved to NY in the beginning of 2007. I am a freelance designer and I do business with clients in New York and Florida. I receive 1099s from my clients, both in New York and Florida, but i am not sure were do I have to file. Could you please clarify this for me? Thank you.

Outlook 2003 - checking data file 'Personal Folders' for problems [ 2 Answers ]

Is there a way to turn this OFF? My computer has a few issues of its own.. nothing that bothers me too bad. Sometimes, it shuts itself down overnight and I usually have evrything still open... like outlook 2003. I know that the problem is NOT with outlook but every time I go to open outlook...


View more questions Search