Thread: About strig comparison

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    3

    About strig comparison



    Dear Sir/Madam,

    I am doing my project in C.I need to develop the string comparison program without using the standard functions.Can you please guide me on this issue?

    Thank you

    S.ashwini

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Can you show us your attempt first?
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    So you're supposed to write your own string comparison function? What have you tried? You basically loop through both the strings, one char at a time, until you find a NUL character or the current chars differs.

  4. #4
    Registered User
    Join Date
    Jun 2010
    Posts
    3

    about string camparison

    Hi,

    I have tried to campare srtings with equal to sign.If i campare single character with equal to sign then is it going work?

    S.ashwini

  5. #5
    Registered User
    Join Date
    Jun 2010
    Posts
    45
    you cant directly compare two strings using the equals sign, you need to compare each character within the string.

    if it makes it easier, it would be the same as comparing these two arrays

    Code:
    int array1[] = {1, 2, 3};
    int array2[] = {1, 2, 4};
    how could you determine whether or not the two arrays contain the same numbers?
    Last edited by LordPc; 06-18-2010 at 07:30 AM.

  6. #6
    Registered User
    Join Date
    Jun 2010
    Posts
    3

    About string comparison

    Hi,

    Thank you sir.I am getting the idea from your reply.I will try this character comparison in my program at home and get back to you later.

    Thank you.

    S.ashwini

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Replies: 3
    Last Post: 05-10-2010, 12:55 AM
  3. std::string comparison versus int comparison
    By leeor_net in forum C++ Programming
    Replies: 3
    Last Post: 04-12-2009, 07:28 AM
  4. Bug in iterator comparison in C++ standard?
    By steev in forum C++ Programming
    Replies: 14
    Last Post: 07-12-2008, 12:02 AM
  5. comparison between pointer and integer
    By bazzano in forum C Programming
    Replies: 3
    Last Post: 03-07-2006, 01:15 PM