objective c - Weird cocoa bug? -


O people, below is a piece of code used for a school assignment. Whenever I put a word, in O (which is the capital), it fails! Whenever this program has one or more capital, then it is false and logs: The sentence is not a villain.

A villain, for people who do not have a cellar, is a word that reads right from left to right, and backwards (for example, Laal, Kayak, Riviera etc.) I found this bug when The 'oldest' pylendrom could be found at any time, to check if: SATOR AREPO TENET OPERA ROTAS

When I change all the Capital O to lowercase o, works, and returns are true. Let me know clearly, all the sentences / words with this piece of code are returning the Capital O return. A single capital o is enough to fail this program.

  - (BOOL) testForPalindrome: (NSString *) Status: (NSInteger) pos {NSString * string = s; NSInteger Status = Status; NSInteger string length = [string length]; NSString * charOne = [string substringFromIndex: position]; Fouron = [charion substringoindexx: 1]; NSString * charTwo = [string substringFromIndex: (stringLength - 1 - position)]; Chartovo = [Chartov substrings toindex: 1]; If (position> (stringLength / 2) {NSString * printableString = [NSString stringWithFormat: @ "D, the following word or sentence is a palindrome: \ n \ n% @", string]; NSLog (@ "% @ is a Palandrome.", String); [TextField setStringValue: Printable string]; Yes come back } If (charOne! = CharTwo) {NSLog (@ "% @,% @", Charonen, Chartuo); NSLog (@ "% i", position); NSLog (@ "% @ is not a palandrome.", String); no return; } Return [Self-test Forlindrom: String status: Position + 1]; }  

So, is it something weird bug in cocoa? Or am I missing something?

  • b

Of course this is a bug in cocoa No, as you probably knew in depth.

Your comparison method is causing the 'bug' in coca, you are comparing the address of Charon and Chartu. Instead, you should compare the contents of the string with exceltoostring messages.

Use:

  If (! [Choice is aquatuit string: Chartu]] {  instead: 

  if (charOne! = CharTwo) Edit: A test project has been tested and can confirm that the problem. 


Comments