Thread: Subtracting Strings

  1. #1
    Registered User
    Join Date
    Oct 2009

    Subtracting Strings

    i had a question. if i needed to subtract two strings( which contain lower case letter words) from one another, how would i approach this or do this? i mean subtract as in:
    i have two strings each contains lower case letters and i want to subtract one from the other as in,subtract 'evil' from 'festival' and getting the characters 'fsta' in return.
    any help would be appreciated.

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    London, United Kingdom
    Not sure if there is such a function in string.h don't think so but you can make your own, however this is a typical pain in the ass in C string manipulation.

    this is the algorithm:

    iterate through the second array (the one you are subtracting){
    get next letter;
    iterate through the first array(the one you are subtracting from){
    find first occurance of letter;
    make another string from array1 without it;
    use pointers and make first array become the new array;
    EDIT: break;
    Last edited by claudiu; 03-16-2010 at 06:21 PM.

  3. #3
    Registered User
    Join Date
    Jan 2009
    Or you could just print all characters from "festival" that is not the characters e,v,i,l.

    What should happen if not all characters are present? Or if a character appear more than once? You might have to make some changes based on the answers of those questions.

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Toronto, ON
    Look for a C regex library online. There should be thousands of them.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  5. #5
    Registered User
    Join Date
    Jan 2009
    Yeah, and you might even have one installed. I have a regex.h that is part of BSD standard library.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 03:24 PM
  2. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 08:07 PM
  3. Subtracting from strings?
    By Xfacter in forum C++ Programming
    Replies: 7
    Last Post: 08-25-2006, 12:01 AM
  4. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 06:37 AM
  5. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 11:23 AM