array indexing

This is a discussion on array indexing within the C Programming forums, part of the General Programming Boards category; I have two loops one for inputting numbers and the other for outputting all the numbers in the array except ...

  1. #1
    Unregistered
    Guest

    array indexing

    I have two loops one for inputting numbers and the other for outputting all the numbers in the array except those entered in the first loop I can do this providing the numbers are it order i.e. 1 2 3...

    I need to do this in random orderi've got.

    int store[25];
    int loop,num=0;

    for (loop=0;loop<25;loop++)
    {
    scanf("%d",&store[loop]);
    fflush(stdin);
    }


    for(num=0;num<25;num++)
    {
    num1++;

    if(num1==store[num])
    continue;

    fputs(store[num],file_ptr);

    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,822
    Not sure if this is what you want, but it does show the kind of things you can do
    Code:
    #include <stdio.h>
    
    #define SIZE    5
    
    int main ( ) {
        int     store[SIZE];
        int     i, j;
        for ( i = 0 ; i < SIZE ; i++ ) {
            scanf( "%d", &store[i] );
        }
        for ( i = 0 ; i < SIZE ; i++ ) {
            int seen = 0;
            for ( j = 0 ; j < i ; j++ ) {   // search all entries before current
                if ( store[j] == store[i] ) {
                    seen = 1;
                    break;
                }
            }
            if ( !seen ) printf( "%d ", store[i] );
        }
        return 0;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 11:33 AM
  2. Replies: 7
    Last Post: 11-25-2008, 01:50 AM
  3. 1-D array
    By jack999 in forum C++ Programming
    Replies: 24
    Last Post: 05-12-2006, 08:01 PM
  4. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 05:15 AM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 09:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21