Thread: Comp Sci Student needs help. Please reply!

  1. #1
    Unregistered
    Guest

    Arrow Comp Sci Student needs help. Please reply!

    I've been working on this project for almost four hours now and I'm freaking out. It should be simple but I just can't figure it out. I need to read integers from a file and store it into an array. Some please help me!

    TonyLFL

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Do you know how many integers you are reading ahead of time?
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    11
    25 integers, both negative and positive.

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    11
    This is what I have so far:

    const int arraySize = 25;
    int a[ arraySize ], number, i;

    ifstream ins( "numbers.dat" );

    while ( ins >> number )
    {
    for ( i = 0; i < arraySize; i++)
    ins >> a[ i ];
    }

    I'm storing all but the first integer in the data file into the array.

  5. #5
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    while ( ins >> number )
    {
    for ( i = 0; i < arraySize; i++)
    ins >> a[ i ];
    }

    replace with..

    for (int i = 0; i < arraySize; i++) {
    ins >> a[i];
    }

    and that should do it...
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    11

    Thumbs up

    Thank you, you have saved my sanity.

    TonyLFL

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Updating in a sequential file?
    By Ronnyv1 in forum C Programming
    Replies: 1
    Last Post: 03-24-2009, 04:41 PM
  2. Database assignment is Killing me!
    By Boltrig in forum C Programming
    Replies: 2
    Last Post: 11-29-2007, 03:56 AM
  3. Comp sci contests
    By Sfel in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 11-20-2007, 04:13 PM
  4. LinkList Sorting in C
    By simly01 in forum C Programming
    Replies: 3
    Last Post: 11-25-2002, 01:21 PM
  5. Creating a student grade book-how?
    By Hopelessly confused in forum C Programming
    Replies: 5
    Last Post: 10-03-2002, 08:43 PM