How to copy one string array to another excluding one string

This is a discussion on How to copy one string array to another excluding one string within the C Programming forums, part of the General Programming Boards category; Hi I have a string array with the following data AAA BBB CCC DDD and I want to copy all ...

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    19

    How to copy one string array to another excluding one string

    Hi

    I have a string array with the following data
    AAA BBB CCC DDD
    and I want to copy all the above data expect BB to another string array. I have the below. inputarray is my source string array and I want to write it to outputarr.
    The problem I have is as seen below where data does not get copied consecutively to outputarr. Can some help me on this? Thanks.

    Code:
    int remBBB(char *inputarray[], char *outputarr[], int count)
    {
    	printf ("In remBBB\n");
    	int x=0; 
    	int count1=0; 
    	char value[MAX_PATH]={NULL}; 
    	sprintf (value,"BBB"); 
    	for (x=0; x < count; x++)
    	{
    		if (strcmp(inputarray[x],value) != 0)
    		{
    			memcpy(outputarr, inputarray, sizeof(outputarr)); 
    			count1++; 
    		}	
    	}
    	return count1++; 
    }

  2. #2
    Registered User
    Join Date
    Dec 2008
    Posts
    19
    Sorry, below is what I have.

    Code:
    int remBBB(char *inputarray[], char *outputarr[], int count)
    {
    	printf ("In remBBB\n");
    	int x=0; 
    	int count1=0; 
    	char value[MAX_PATH]={NULL}; 
    	sprintf (value,"BBB"); 
    	for (x=0; x < count; x++)
    	{
    		if (strcmp(inputarray[x],value) != 0)
    		{
    			memcpy(outputarr[x], inputarray[x], sizeof(outputarr[x])); 
    			count1++; 
    		}	
    	}
    	return count1++; 
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. string array v.s. int array
    By George2 in forum C++ Programming
    Replies: 2
    Last Post: 12-10-2007, 11:07 PM
  2. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 03:13 PM
  3. Copying a string, into a string array.
    By m.mixon in forum C Programming
    Replies: 5
    Last Post: 07-31-2006, 05:19 PM
  4. can't assign proper values to an array of string
    By Duo in forum C Programming
    Replies: 1
    Last Post: 04-04-2005, 06:30 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM

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