Script started on Wed 04 Feb 2015 03:41:12 PM PST bash-4.2$ gcc -g -o reverse reverse3.c bash-4.2$ gdb reverse GNU gdb (GDB) Fedora 7.6.1-46.fc19 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-redhat-linux-gnu". For bug reporting instructions, please see: ... Reading symbols from /homes/bdmyers/cse374_demos/11/reverse...done. # From staring at the code and thinking about the previous # error in reverse2.c, we hypothesized that the newline is # being swapped with the first character. # We check this by navigating to the point where we have # the result of reverse() (gdb) break reverse Breakpoint 1 at 0x4006ec: file reverse3.c, line 21. (gdb) run Starting program: /homes/bdmyers/cse374_demos/11/reverse Please enter a string: 1234 Breakpoint 1, reverse (s=0x7fffffffe2e0 "1234\n") at reverse3.c:21 21 char * result = NULL; /* the reversed string */ Missing separate debuginfos, use: debuginfo-install glibc-2.17-20.fc19.x86_64 (gdb) finish Run till exit from #0 reverse (s=0x7fffffffe2e0 "1234\n") at reverse3.c:21 0x00000000004007d4 in main () at reverse3.c:55 55 rev_line = reverse(line); Value returned is $1 = 0x602010 "\n4321" (gdb) step # We print the memory pointed to by rev_line and # indeed find that the newline became the first character. # There are several ways to fix this. reverse4.c shows one way 57 printf("The original string was: >%s<\n", line); (gdb) x /10c rev_line 0x602010: 10 '\n' 52 '4' 51 '3' 50 '2' 49 '1' 0 '\000' 0 '\000' 0 '\000' 0x602018: 0 '\000' 0 '\000' (gdb) quit A debugging session is active. Inferior 1 [process 21056] will be killed. Quit anyway? (y or n) y bash-4.2$ exit exit Script done on Wed 04 Feb 2015 03:42:01 PM PST