Thread: String Function Question

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    24

    String Function Question

    Would there be a string function for the following ?!

    Compares two strings for equality. If they are equal, zero is returned,
    otherwise the difference in value between the first two non-matching characters.

    AND

    Takes two strings as arguments. If the first exists in the second as a substring, return a pointer to the first occurrence, otherwise zero.

    Thanks

    devilsknight

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    1 - No. strcmp is as close as you get, but it doesn't return the difference between the first two non-matching characters.
    2 - Yes, strstr is what you want.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    124
    No. strcmp is as close as you get, but it doesn't return the difference between the first two non-matching characters.
    However, it does return a negative number if string1 < string2 or a positive non-zero number if string1 > string2.
    I think you can put a signature here.

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Sounds like homework to me.
    If you understand what you're doing, you're not learning anything.

  5. #5
    Registered User
    Join Date
    Jun 2006
    Posts
    24
    it is homework...but i wasnt asking for someone to code it for me

    i was asking for help on which function i should use...i'll be doing the rest of the program...is there a problem with that ?

    btw thanks for your help guys...

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by devilsknight
    i was asking for help on which function i should use...
    Only the one you write -- it's as basic than some of the standard functions, so there's really nothing lower to build from (unless you want to make it icky).

    I could give you a hint, but try to implement this function yourself first.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  2. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  5. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM