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)
(gdb) q The program is running. Exit anyway? (y or n) y $