problem with arrays

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • holla
    New Member
    • Mar 2007
    • 22

    problem with arrays

    could u pls guys help me with this problem
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #define MIN_SIZE1 20
    #define MIN_SIZE2 20
    #define MAX_SIZE 40
    
    int populate_an_array(int array[], int array_size);
    void remove_duplicates(int array[], int array_size);
    void sort_array(int array[],int array_size);
    int merge_the_contents(int array[],int array_size,int arr2,int array_size2,int result[]);
    int search_value(int array[],int array_size,int number);
    
    int main()
    {
    	int array1[MIN_SIZE1];
    	int array2[MIN_SIZE2];
    	int number;
    	int result_arr[MIN_SIZE1+MIN_SIZE2];
    	int i;
    
    
    populate_an_array(array1, MIN_SIZE1);
    populate_an_array(array2, MIN_SIZE2);
    
    	remove_duplicates(array1, MIN_SIZE1);
        remove_duplicates(array2, MIN_SIZE2);
    
    sort_array(array1, MIN_SIZE1);
    sort_array(array2, MIN_SIZE2);
    
    	merge_the_contents(array1,MIN_SIZE1,array2, MIN_SIZE2,result_arr);
    
    
    
    	remove_duplicates(result_arr,(MIN_SIZE1+MIN_SIZE2));
    	sort_array(result_arr,(MIN_SIZE1+MIN_SIZE2));
    	for(i=0;i<MAX_SIZE;i++)
    	{printf("%d,\n", result_arr[i]);
    		}
    		printf("enter the number");
    		scanf("%d\n",&number);
    
    			search_value(result_arr,(MIN_SIZE1+MIN_SIZE2),number);
    
    return 0;
    }
    int populate_an_array(int array[], int array_size)
    {
    	int i;
    	randomize();
    	for (i=0;i<array_size;i++)
    	{array[i]=rand()%100;}
    	return *array;
    	}
    
    
    	int remove_duplicate(int array[],int array_size)
    	{
    	int i,j;
    	for (i= 0;i<array_size;i++)
    	{
    		for(j =0;j =array_size;j++)
    		{
    			if (j !=i){
    			if (array[i]=array[j]){
    				array[j] =rand()%100;
    				}
    			}
    		}
    	}
    
    		return *array;
    }
    
    
    void sort_array(int array[], int array_size)
    	{
    	int i,j,temp;
    
    
    			for(i=0;i< array_size-1;i++)
    for(j=i+1;j<array_size;j++){
    if(array[i]>array[j]){
    	temp=array[i];
    	array[i]=array[j];
    	array[j] =temp;
    	}
    }
    }
    
    int merge_the_contents(int array[],int array_size,int arr2,int array_size2,int result[])
    {
    int i,j;
    
    for(i=0;i<array_size;i++)
    {
    result[i]=array[i];
    	}
    	for (j=0;j<array_size;j++)
    	{
    	result[(array_size2 + j)] = arr2[j];
    	}
    	return *result;
    }
    
    	 int search_value(int array[],int array_size,int number){
    
    int low = 0, high = array_size, mid,found=0;
    
    
    while (low < high) {
    	mid = (low + high) / 2;
    	if (array[mid] < number)
    	    low = mid + 1;
         else
              high = mid;
         }
    	 if(found==1)
    		 printf("the number is \"%d\" is found",number);
    	 else
    		 printf("the number \"%d\" is not found",number);
    Last edited by horace1; Mar 16 '07, 01:35 PM. Reason: added code tags
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    for a start
    Code:
    int merge_the_contents(int array[],int array_size,int arr2,int array_size2,int result[])
    should parameter 3 be an int[], e.g.
    Code:
    int merge_the_contents(int array[],int array_size,int arr2[],int array_size2,int result[])

    Comment

    • holla
      New Member
      • Mar 2007
      • 22

      #3
      Originally posted by horace1
      for a start
      Code:
      int merge_the_contents(int array[],int array_size,int arr2,int array_size2,int result[])
      should parameter 3 be an int[], e.g.
      Code:
      int merge_the_contents(int array[],int array_size,int arr2[],int array_size2,int result[])
      thanks man but there is one error:
      Call to function 'search_value' with no prototype in function main.I JUST CANT FIGURE OUT WHAT TO DO

      Comment

      • horace1
        Recognized Expert Top Contributor
        • Nov 2006
        • 1510

        #4
        Originally posted by holla
        thanks man but there is one error:
        Call to function 'search_value' with no prototype in function main.I JUST CANT FIGURE OUT WHAT TO DO
        I don't get that error - there is prototype at the top of the program
        Code:
        int search_value(int array[],int array_size,int number);
        I get a [Linker error] undefined reference to `remove_duplica tes' and `randomize'

        Comment

        • holla
          New Member
          • Mar 2007
          • 22

          #5
          Originally posted by horace1
          I don't get that error - there is prototype at the top of the program
          Code:
          int search_value(int array[],int array_size,int number);
          I get a [Linker error] undefined reference to `remove_duplica tes' and `randomize'
          now i get a syntax error for :
          int search_value(in t array[],int array_size,int number);

          Comment

          • horace1
            Recognized Expert Top Contributor
            • Nov 2006
            • 1510

            #6
            Originally posted by holla
            now i get a syntax error for :
            int search_value(in t array[],int array_size,int number);
            very strange - taking the code in your first post I fix the line
            Code:
            int merge_the_contents(int array[],int array_size,int arr2[],int array_size2,int result[])
            and it compiles OK with [Linker error] undefined reference to `remove_duplica tes' and `randomize'

            what compiler are you using?

            Comment

            • holla
              New Member
              • Mar 2007
              • 22

              #7
              Originally posted by horace1
              very strange - taking the code in your first post I fix the line
              Code:
              int merge_the_contents(int array[],int array_size,int arr2[],int array_size2,int result[])
              and it compiles OK with [Linker error] undefined reference to `remove_duplica tes' and `randomize'

              what compiler are you using?
              i am using SCITE-A SCINTILLA BASED TEXT EDITOR

              Comment

              • holla
                New Member
                • Mar 2007
                • 22

                #8
                Originally posted by holla
                i am using SCITE-A SCINTILLA BASED TEXT EDITOR
                i have done again but it cant compile well:
                Code:
                #include <stdio.h>
                #include <stdlib.h>
                #define MIN_SIZE1 20
                #define MIN_SIZE2 20
                #define MAX_SIZE 40
                
                int populate_an_array(int array[], int array_size);
                void remove_duplicates(int array[], int array_size);
                void sort_array(int array[],int array_size);
                int merge_the_contents(int array[],int array_size,int arr2[],int array_size2,int result[]);
                int search_value(int array[],int array_size,int number);
                
                int main()
                {
                	int array1[MIN_SIZE1];
                	int array2[MIN_SIZE2];
                	int number;
                	int result_arr[MIN_SIZE1+MIN_SIZE2];
                	int i;
                
                
                populate_an_array(array1, MIN_SIZE1);
                populate_an_array(array2, MIN_SIZE2);
                
                	remove_duplicates(array1, MIN_SIZE1);
                    remove_duplicates(array2, MIN_SIZE2);
                
                sort_array(array1, MIN_SIZE1);
                sort_array(array2, MIN_SIZE2);
                
                	merge_the_contents(array1,MIN_SIZE1,array2, MIN_SIZE2,result_arr);
                
                
                
                	remove_duplicates(result_arr,(MIN_SIZE1+MIN_SIZE2));
                	sort_array(result_arr,(MIN_SIZE1+MIN_SIZE2));
                	for(i=0;i<MAX_SIZE;i++)
                	{printf("%d,\n", result_arr[i]);
                		}
                		printf("enter the number");
                		scanf("%d\n",&number);
                
                			search_value(result_arr,(MIN_SIZE1+MIN_SIZE2),number);
                
                return 0;
                }
                int populate_an_array(int array[], int array_size)
                {
                	int i;
                	randomize();
                	for (i=0;i<array_size;i++)
                	{array[i]=rand()%100;}
                	return *array;
                	}
                
                
                	int remove_duplicate(int array[],int array_size)
                	{
                	int i,j;
                	for (i= 0;i<array_size;i++)
                	{
                		for(j =0;j<array_size;j++)
                		{
                			if (j !=i)
                			{
                			if (array[i]=array[j])
                				{
                				array[j] =rand()%100;
                				}
                			}
                		}
                	}
                
                		return *array;
                }
                
                
                void sort_array(int array[], int array_size)
                	{
                	int i,j,temp;
                
                
                			for(i=0;i< array_size-1;i++)
                for(j=i+1;j<array_size;j++){
                if(array[i]>array[j]){
                	temp=array[i];
                	array[i]=array[j];
                	array[j] =temp;
                	}
                }
                }
                
                int merge_the_contents(int array[],int array_size,int arr2[],int array_size2,int result[])
                {
                int i,j;
                
                for(i=0;i<array_size;i++)
                {
                result[i]=array[i];
                	}
                	for (j=0;j<array_size;j++)
                	{
                	result[(array_size2 + j)] = arr2[j];
                	}
                	return *result;
                }
                
                	 int search_value(int array[],int array_size,int number){
                
                int low = 0, high = array_size, mid,found=0;
                
                
                while (low < high) {
                	mid = (low + high) / 2;
                	if (array[mid] < number)
                	    low = mid + 1;
                     else
                          high = mid;
                     }
                	 if(found==1)
                		 printf("the number is \"%d\" is found",number);
                	 else
                		 printf("the number \"%d\" is not found",number);
                 return 0;}
                Last edited by Ganon11; Mar 16 '07, 03:49 PM. Reason: code tags added

                Comment

                • Ganon11
                  Recognized Expert Specialist
                  • Oct 2006
                  • 3651

                  #9
                  Please don't post again on the same topic - you may continue to receive help in this thread. A second thread is not necessary.

                  Comment

                  Working...