Question

In: Computer Science

Part II: gdb (Debugging under Unix) create a new directory named by Inlab6Part2 enter the directory...

Part II: gdb (Debugging under Unix)

  1. create a new directory named by Inlab6Part2
  2. enter the directory Inlab6Part2
  3. create a file named by reverse_new.c with the following contents:

/*reverse.c */

#include <stdio.h>

void reverse(char *before, char *after);

main()

{

      char str[100];    /*Buffer to hold reversed string */

      reverse("cat", str); /*Reverse the string "cat" */

      printf("reverse(\"cat\")=%s\n", str); /*Display result */

      reverse("noon", str); /*Reverse the string "noon" */

      printf("reverse(\"noon\")=%s\n", str); /*Display result */

     

}

void reverse(char *before, char *after)

{

      int i;

      int j;

      int len;

      len=strlen(before);

      for(j=len, i=0; j>=0; j--, i++)

                  after[i]=before[j];

      after[len]=NULL;

}

  1. See the output, is it right?
  2. compile reverse_new.c and prepare the debugger information at the same time.(To debug a program, it must have been compiled using the –g option to gcc, which places debugging information into the object module.)
  3. Now you start the debugger and fix the errors.
    1. set breakpoint in line 1 and then go through step by step, print the value of arguments after each step.
    2. make sure you use most of the commands in the handout, and then print everything you did(all the commands and outputs).

Solutions

Expert Solution

The program after removing the errors is below:

#include <stdio.h>

void reverse(char *before, char *after);

void main()

{

      char str[100];    /*Buffer to hold reversed string */

      reverse("cat", str); /*Reverse the string "cat" */

      printf("reverse(\"cat\")=%s\n", str); /*Display result */

      reverse("noon", str); /*Reverse the string "noon" */

      printf("reverse(\"noon\")=%s\n", str); /*Display result */

     

}

void reverse(char *before, char *after)

{

      int i;

      int j;

      int len;

      len=strlen(before);

      for(j=len-1, i=0; j>=0; j--, i++)

                  after[i]=before[j];

      after[len]=NULL;

}

The only change in the code is that 'j' variable inside for loop of reverse() is initialized to len-1 instead of len;

The debug console screen is as below:


Related Solutions

UNIX/LINUX SCRIPT: Create a named directory and verify that the directory is there by listing all...
UNIX/LINUX SCRIPT: Create a named directory and verify that the directory is there by listing all its contents. Write a shell script to validate password strength. Here are a few assumptions for the password string.   Length – a minimum of 8 characters. • Contain alphabets , numbers , and @ # $ % & * symbols. • Include both the small and capital case letters. give a prompt of Y or N to try another password and displays an error...
Using PyCharm, create a new Project lab8. Under lab8 create a new Directory exercise, then create...
Using PyCharm, create a new Project lab8. Under lab8 create a new Directory exercise, then create a Python file called nested.py, type the following: Test your code by putting the following at the bottom of the file: make_table_of_stars(2,3) (as shown in the code above). Run the file by right clicking in the code area of Pycharm, then choosing “Run nested”. Your output should be: *** *** (2 rows with 3 columns of stars). Reverse the 2 and 3. What happens?...
Create a console application named TakeHomePay.cs under your homework directory (please refer to the earlier recorded...
Create a console application named TakeHomePay.cs under your homework directory (please refer to the earlier recorded Zoom sessions if you are not sure how to do it) that calculates the take-home pay for an employee. The two types of employees are salaried and hourly. Allow the user to input the employee’s first and last name, id, and type. If an employee is salaried, allow the user to input the salary amount. If an employee is hourly, allow the user to...
In the funcs directory create a file named funcs.py. This section requires that you implement and...
In the funcs directory create a file named funcs.py. This section requires that you implement and test multiple functions. You should develop these functions and their tests one at a time. The function implementations must be placed in funcs.py. The test cases will, of course, be placed in the provided funcs_tests.py. You must provide at least two test cases for each of these functions. In addition, you should separate your testing into multiple functions (the file includes stubs for the...
how to create s recursive function, explore that prompts the user to enter a directory name...
how to create s recursive function, explore that prompts the user to enter a directory name and an executable name, and checks that they are both readable and executable (terminating with an error message if not). It then passes the two names to the explore function. this is a part of bash scripting.
An exceptions lab. Create a new class named EnterInfo Request user enter name and age Accept...
An exceptions lab. Create a new class named EnterInfo Request user enter name and age Accept a string and an int Use custom Exception to warn user when name is blank Use custom Exception to warn user when age is invalid 0 > age > 120 Use general Exception to warn user when age is not an int Loop through until user enters all valid data
Object-Oriented Design and Patterns in Java (the 3rd Edition Chapter 5) - Create a directory named...
Object-Oriented Design and Patterns in Java (the 3rd Edition Chapter 5) - Create a directory named as the question number and save the required solutions in the directory. - Each problem comes with an expected tester name. In the directory for a given problem, including the tester and all java classes successfully run this tester. Exercise 5.2 ObserverTester.java - Improve Exercise 1 by making the graph view editable. Attach a mouse listener to the panel that paints the graph. When...
Create a file named work.sh in your hw5 directory. Give this file read and write permission...
Create a file named work.sh in your hw5 directory. Give this file read and write permission (no execute permissions) for you alone. No other account should have any access privileges to this file. Change the permissions on the work.sh file so you have read and write permissions. Give everybody else, including the group, read permissions only. Give yourself read, write and execute permissions to the file work.sh. Give everyone else, including the group, execute permissions only. Create a directory named...
In STS, create Java Project, called java_generics_yourNameLastname that; (Under source directory called, src, create a package...
In STS, create Java Project, called java_generics_yourNameLastname that; (Under source directory called, src, create a package csci3444.generics and put all code in it) Create a generic interface called “MyGenInterface” that takes 2 generic types K,V with below methods; public K getKey(); public V getValue(); Create a generic class called “MyGenClass” that implements “MyGenInterface” interface. has attributes “K key” and “V value” that can be inherited has a constructor that takes “K _key”, “V _value” inputs and initializes “key”, “value” attributes...
PYTHON PROGRAM Requirements: 1. Create an empty directory a variable named song_search 2. Repeatedly prompt the...
PYTHON PROGRAM Requirements: 1. Create an empty directory a variable named song_search 2. Repeatedly prompt the user to enter either the title of a song or enter nothing if they have no more songs to enter 3. For each song title entered by the user, split the song title into words by using the split function and splitting on a space. For each word from each song title, ensure the song_search dictionary has a entry with that word as the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT