Thread: strcat: is there an ANTIstrcat!?

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    108

    Question strcat: is there an ANTIstrcat!?

    strcat joins two strings together but i wanted to know if there is a option that does the reverse.

    i.e. if we had

    Code:
    string1[] = "1, 2, 3, 4, 5, 6"
    and

    Code:
    string2[] = "1, 2, 3"
    then the output would be

    Code:
    5, 6
    in a new string.

    anyone know of a method?

  2. #2
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    Posts
    236
    strtok, used with a little care.
    Demonographic rhinology is not the only possible outcome, but why take the chance

  3. #3
    .
    Join Date
    Nov 2003
    Posts
    307
    strspn(stringa, stringb ) returns the offset of the first character in stringb that is not found anywhere in stringa.

  4. #4
    ---
    Join Date
    May 2004
    Posts
    1,379
    strspn is non standard
    A function like this shouldn't be too hard to implement yourself. Why don't you give it a go?

  5. #5
    .
    Join Date
    Nov 2003
    Posts
    307
    Quote Originally Posted by sand_man
    strspn is non standard
    A function like this shouldn't be too hard to implement yourself. Why don't you give it a go?
    That's odd - It was part of the ANSI C89 standard. I don't have ISO C standard around. Has it been dropped - sounds unlikley.

  6. #6
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    Yep, its still there:

    7.21.5.6

    The strspn function

    Synopsis

    1 #include <string.h>
    size_t strspn(const char *s1, const char *s2);

    Description

    2 The strspn function computes the length of the maximum initial segment of the string pointed to by s1 which consists entirely of characters from the string pointed to by s2.

    Returns

    3 The strspn function returns the length of the segment.
    Last edited by kermit; 06-29-2005 at 08:35 AM.

  7. #7
    Registered User
    Join Date
    Jun 2005
    Posts
    108
    guys, thanks for the replies, i gave it a go and got partial success.

    the problem is that the strtok deletes every occurance of a letter or number, i only want exact matches deleted.

    otherwise its absolutely perfect

    the is my attempt

    Code:
    #include <stdio.h>
    #include <string.h>
    
    //***reads input one character at a time from the input stream 
    //   and puts into string called "uncoded"***//
    
    char uncoded[BUFSIZ] = "#RAWWAASFRAMEA,COM1,9,68.0,SATTIME,1263,128186.000,000000000,58e4,1522,22,122,62,563456345dba43623443efdaef3245345fea325345626634623623c000,22*d04567cde";	
    
    //char uncodedraaw[BUFSIZ] = "#RAWWAASFRAMEA, COM1, COM2,00000000, 58e4, 122, 22";
    
    char uncodedraaw[BUFSIZ] = "#RAWWAASFRAMEA, SATTIME, COM1";
    
    //   char *token;
    
    char *decoded;
    
    
    void main()
    
    {
    
    printf( "remaining data:\n" );
    
    decoded = strtok( uncoded, uncodedraaw );
    
    while( decoded != NULL )
       {
          /* While there are tokens in "string" */
          printf( " %s", decoded );
          /* Get next token: */
          decoded = strtok( NULL, uncodedraaw );
       }
    
    }

  8. #8
    ---
    Join Date
    May 2004
    Posts
    1,379
    Quote Originally Posted by jim mcnamara
    That's odd - It was part of the ANSI C89 standard. I don't have ISO C standard around. Has it been dropped - sounds unlikley.
    Sorry for the false information, I had a quick glance but couldn't find it so I thought it was non standard.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An interesting question about strcat
    By meili100 in forum C++ Programming
    Replies: 3
    Last Post: 07-07-2009, 12:59 PM
  2. argv change
    By dracayr in forum C Programming
    Replies: 9
    Last Post: 04-10-2009, 02:49 AM
  3. strcat and a char
    By jjacobweston in forum C++ Programming
    Replies: 2
    Last Post: 05-09-2005, 04:10 PM
  4. strcat makes program crash
    By imoy in forum C++ Programming
    Replies: 4
    Last Post: 05-09-2002, 02:41 PM
  5. Removing 'strcat' ed string.
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 11-14-2001, 12:09 AM