Thread: Trouble with a simple array

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    What are "items"? If they're all of the same type, like integers, you can declare the array like so:
    Code:
    int file[100];
    Then just read the file like you normally do and assign to each index in the array:
    Code:
    /* Gather numbers from the file */
    for ( i = 0; i < 100; i++ ) {
      if ( fscanf ( in, "%d", &file[i] ) != 1 )
        break;
    }
    
    /* Display gathered numbers */
    for ( j = 0; j < i; j++ )
      printf ( "%d\n", file[j] );
    Last edited by Prelude; 10-27-2005 at 02:30 PM.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. base address of a simple array
    By nacho4d in forum C Programming
    Replies: 13
    Last Post: 04-07-2008, 01:28 PM
  2. Simple 2 dimensional array problem
    By AmbliKai in forum C Programming
    Replies: 4
    Last Post: 10-30-2007, 05:49 AM
  3. simple Array question.
    By Fredir in forum C++ Programming
    Replies: 6
    Last Post: 10-06-2007, 07:12 AM
  4. Template Array Class
    By hpy_gilmore8 in forum C++ Programming
    Replies: 15
    Last Post: 04-11-2004, 11:15 PM
  5. A simple question about selecting elements in an array
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 08-30-2001, 10:37 PM