Thread: remove strings from array

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    52

    remove strings from array

    Hi all!
    I'm having a trouble to exclude (substitute with the next string) repeated strings from an array:

    Code:
    char hst[30][30];  /* stored strings */
    int qt_hst; /* amount of strings at hst */
    int rptds[10]; /* store which lines numbers are repeated strings */
    int a, b; 
    ...
    
    a = b = 0;
    while (b = rptds[a])
    {
    	for (b; b<=qt_hst; b++)
    		strcpy(hst[b-a], hst[b-a+1]);
    	a++; qt_hst--;
    }
    But this code don't work properly. Mainly if the rptds[x] > rptds[x+1]

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    > while (b = rptds[a])

    Should probably be: while (b == rptds [a])

    > b<=qt_hst

    You realise that arrays have first index being 0, so perhaps it should be b < qt_st?

    > strcpy(hst[b-a], hst[b-a+1]);

    You could do a little debugging by printing the values of b-a and b-a+1 and then check if those values are not above 30, which is the maximum number of stored strings.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    52
    >> while (b = rptds[a])
    > Should probably be: while (b == rptds [a])
    no. is really b = rptds[a]

    > b<=qt_hst
    You realise that arrays have first index being 0, so perhaps it should be b < qt_st?
    the counter also starts on 0.

    > strcpy(hst[b-a], hst[b-a+1]);

    >You could do a little debugging by printing the values of b-a and b-a+1 and then check if those values are not above 30, which is the maximum number of stored strings.

    I already did. I couldn't find the bug.
    Please, let me know if someone have a solution for this code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. intializing an array of strings
    By doubty in forum C Programming
    Replies: 4
    Last Post: 06-19-2009, 12:59 PM
  2. Replies: 1
    Last Post: 03-19-2009, 10:56 AM
  3. Build an array of strings dynamically
    By Nazgulled in forum C Programming
    Replies: 29
    Last Post: 04-07-2007, 09:35 PM
  4. Passing an Array of Strings from VB to a C DLL
    By mr_nice! in forum Windows Programming
    Replies: 9
    Last Post: 03-08-2005, 06:16 AM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM