Thread: string comparing question..

  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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    don't you think this: st1++; could slightly change value of st1?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    aaabbbcccdd and abcd
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  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, 06: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