Thread: Array Comparison and Modification

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    32

    Array Comparison and Modification

    This is what my code is intended to do: When called with the following array:
    Code:
    { 1, 1, 1, 2, 2, 1, 2, 3, 3, 1, 1 }
    , your function should modify the array to
    Code:
    {1, 2, 1, 2, 3, 1}
    and store it.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    void compact (int[], int);
    int main()
    {
        int arrSeries[11] = {1, 1, 1, 2, 2, 1, 2, 3, 3, 1, 1 };
        int arrLength = 11;
        compact(arrSeries, arrLength);
        getchar();
        return 0;
    }
    
    
    void compact(int arrSeries[], int arrLength)
    {
        int i, j= 0, counter=0, newArray[11];
        newArray[0]=arrSeries[0];
        for(i = 1; i != arrLength; i++)
        {
            if(newArray[j] != arrSeries[i-1]);
            {
                newArray[++j] = arrSeries[i];
            }
    
    
        }
    
    
        while(counter !=6)
        {
            printf("%d  ", newArray[counter]);
            counter++;
        }
    
    
    }
    However it is not working as intended. It works as if the IF statement doesn't even exist ! Where am I going wrong?
    Thanks
    Last edited by Debojyoti Das; 12-21-2012 at 08:31 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Character Array Comparison
    By programit in forum C Programming
    Replies: 2
    Last Post: 01-31-2011, 12:30 PM
  2. Help on array comparison
    By sivapc in forum C++ Programming
    Replies: 6
    Last Post: 11-10-2009, 09:54 AM
  3. Scanf confusion, 2 dimensional array modification
    By Leojeen in forum C Programming
    Replies: 23
    Last Post: 10-19-2008, 10:58 PM
  4. array comparison
    By cloudy in forum C Programming
    Replies: 2
    Last Post: 10-16-2004, 02:45 PM
  5. array comparison
    By battoujutsu in forum C Programming
    Replies: 12
    Last Post: 12-05-2003, 11:47 AM

Tags for this Thread