Thread: Efficiency problem

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    7

    Question Efficiency problem

    I never thanked whoever helped me last time I had a problem, so thanks to the people who helped me. I no longer make function calls prefixed by their data types. *cough*

    Anyway, I'll illustrate my new problem first.

    for(row = 0; row < ROWS; row++)
    {
    fscanf(p5, "%d %d %d %d %d %d", &studentID[row], &test1, &test2, &test3, &test4, &test5);
    for(column = 0; column < COLUMNS; column++)
    {
    testScores[row][0] = test1;
    testScores[row][1] = test2;
    testScores[row][2] = test3;
    testScores[row][3] = test4;
    testScores[row][4] = test5;
    }
    } // where ROWS = 40 and COLUMNS = 5

    Two questions. First, is there a more efficient way to shove the test variables in the array testScores? I've experimented (for hours) but I must have missed something in class.
    Second, when I run the program which eventually prints the arrays, I can't figure out a way to cut out the excess data. Since only 15 rows of 40 are printed to, is there a way to flag this to stop after if reaches the end of the input but be flexible enough to hold a max of 40? I'm not sure if I'm explaining my problem correctly, but any help would be greatly appreciated.

  2. #2
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    maybe you can use a loop?

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    > Two questions. First, is there a more efficient way to shove the
    > test variables in the array testScores? I've experimented (for
    > hours) but I must have missed something in class.

    Efficient how? Less typing for you, or less processor time?

    Less typing is to use a loop.
    Less processor time is to not use a loop and just assign them all with individual assignments.

    However, since you aren't doing anythign specific with your 'test*' values, why are you even bothering using them?
    Code:
    fscanf( p5, "%d %d %d %d %d %d",
        &studentID[row],
        &testScore[row][0],
        &testScore[row][1],
        &testScore[row][2],
        &testScore[row][3],
        &testScore[row][4]
        );
    >Second, when I run the program which eventually prints the
    > arrays, I can't figure out a way to cut out the excess data.
    > Since only 15 rows of 40 are printed to, is there a way to flag
    > this to stop after if reaches the end of the input but be flexible
    > enough to hold a max of 40? I'm not sure if I'm explaining my
    > problem correctly, but any help would be greatly appreciated

    What do you mean exactly? It scrolls off the screen and you
    want it to pause between each "page"?

    Print 15, read a key, print the next 15 .... repeat.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    7
    I understand the first part, and thanks. BTW, I have to average each row and column, so that's another reason I put them into variables. Let me see if I can explain the second part better.

    The array testScores is two-dimensional with 5 columns and a possible maximum of 40 rows. For the project, only 15 rows will be read when we submit it. But when I print the array, the 15th line of input is printed until 40 rows are printed. I want the max number of rows to be 40, but I only want it to print however many are valid data(I initialized the whole array to 0 when I declared it).

    Does that make more sense?

    Thanks again
    Last edited by BlackCitan; 03-23-2002 at 12:49 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM