Program Debugging
Print this page
  • Why ? It is comparing 'm' and '\0'. It is suppose to compare 'm' and 'm' , which are first and last character of the input string. Check indexes used to compare? That is, i and length - i .

    (gdb) print i
    $5 = 0
    (gdb) print length-i
    $6 = 5
    (gdb)

  • Index of an array of length 5 varies between 0 and 4. But we are comparing the character stored in the indexes 0 and 5, which is not correct.
  • Index should be used in the right expression should be length-i-1 .
  • Quit the gdb.

    (gdb) q
    The program is running. Exit anyway? (y or n) y
    $

  • Edit the program, compile, and execute.
  • Now, the program works correctly.
 
Prev