string comparing question..

This is a discussion on string comparing question.. within the C Programming forums, part of the General Programming Boards category; what this function does Code: int what(char *st1, char *st2){ char *p = st1; if(*st2 || *st1){ if(*st1 == '

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    string comparing question..

    what this function does
    Code:
    int what(char *st1, char *st2){
    	char *p = st1;
    
    	if(*st2 || *st1){
    		if(*st1 == '\0') return 0;
    		while(*st1 && *st2 && *st1==*st2) st1++;  //it stops on the place
                                                                                           //where st1 differs str2
    		if(st1==p) return 0;                        //it always will return 0 because
                                                                          //we defined char *p = st1;
    		return what(st1, st2+1);
    	}
    	else
    		return 1;
    }
    so it will always return 0 and not going to the recursive line
    ??

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    don't you think this: st1++; could slightly change value of st1?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    st1++ make the array to decay from the next place
    but they didnt do it for st2
    so they check if all the chars in st1 equal the current char of st2
    if we have one char in st1 which differs the "zero" cell then
    it check for the same thing but st2 decays on the next cell in its array

    i cant understand what is the purpose of this??

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    aaabbbcccdd and abcd
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    i traced it
    i get 0 in the output

    how do i get to the purpose??

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  2. RicBot
    By John_ in forum C++ Programming
    Replies: 8
    Last Post: 06-13-2006, 07:52 PM
  3. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
  4. String array question
    By gogo in forum C++ Programming
    Replies: 6
    Last Post: 12-08-2001, 06:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21