Question

can you please do this lab? use lunix or C program its a continuation of a...

can you please do this lab? use lunix or C program

its a continuation of a previous lab.

the previous lab:

Unix lab 4: compile and link multiple c or c++ files

Please do the following tasks step by step:

  1. create a new directory named by inlab4
  2. enter directory inlab4
  3. create a new file named by reverse.c with the following contents and then close the file:

/*reverse.c */

#include <stdio.h>

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 */

     

}

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;

}

  1. type the following three commands and copy the results to a file which you will submit at the end of the lab:

gcc reverse.c –o reverse compile reverse.c to a file named reverse

ls –l reverse                list the information of file named by reverse

./reverse                                         run the executable file “reverse”

  1. create a new file named by reverse.h with the following contents:

/* reverse.h */

reverse(char *before, char *after); /* declare but do not define this function */

  1. modify your file of reverse.c to the following contents:

/*reverse.c */

#include <stdio.h>

#include "reverse.h"

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;

}

  1. create a new file named by main1.c with the following contents:

/*main.c */

#include <stdio.h>

#include "reverse.h"

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 */

     

}

  1. type the following five commands and copy the results to your file which you will submit.

gcc –c reverse.c            compile reverse.c to a file named reverse.o

gcc –c main1.c                compile main1.c to a file named main1.o

ls –l reverse.o main1.o

gcc reverse.o main1.o –o main1                      link object modules

main1                                                             run the executable file

- the new lab that i need help with:

Note: This inlab assignment is based on Unix lab Assignment 4.

Please do the following tasks step by step:

  1. Log on your Unix account.
  2. List all the directory and files under the current path, and you will find a directory named by inlab4. This is produced from our Unixlab4 Assignment.
  3. copy all the contents of inlab4 to inlab6 (create the directory if you don’t have it), you can use the following command:

cp –r inlab4 inlab6

  1. create a new file named by palindrome.h

/* PALINDROME.H */

int palindrome(); /* Declare but do not define */

  1. create a new file named by palindrome.c:

/* palindrome.c */

#include "palindrome.h"

#include "reverse.h"

#include <string.h>

/*****************************************/

int palindrome(char *str)

{

        char reversedStr[100];

        reverse(str, reversedStr); /*Reverse original */

        return (strcmp(str, reversedStr)==0); /* compare the two */

}

  1. create a new file named by main2.c:

/* main2.c */

#include <stdio.h>

#include "palindrome.h"

/*****************************************************/

main()

{

        printf("palindrome (\"cat\") = %d\n", palindrome("cat"));

        printf("palindrome (\"noon\") = %d\n", palindrome("noon"));

}

  1. use the method we have used in lab4 to compile palindrome.c and main2.c, link all needed files and then run main2.
  2. Now if you modify a little bit for reverse.c, then you have to recompile reverse.c, recompile palindrome.c, recompile main2.c, relink three objective files and then rerun it. That is, you have to retype four commands. Now we create a makefile and then put these commands in one file, and you can use one command to run these four commands.
  3. create a new file named main1.make with the following contents:

main1:                  main1.o reverse.o

                              cc main1.o reverse.o -o main1

main1.o:               main1.c reverse.h

                              cc -c main1.c

reverse.o:             reverse.c reverse.h

                              cc -c reverse.c

  1. create a new file named main2.make with the following contents:

main2:                  main2.o reverse.o palindrome.o

                              cc main2.o reverse.o palindrome.o -o main2

main2.o:               main2.c palindrome.h

                              cc -c main2.c

reverse.o:             reverse.c reverse.h

                              cc -c reverse.c

palindrome.o:      palindrome.c palindrome.h reverse.h

                              cc -c palindrome.c

  1. type the following command and see the result

make –f main1.make

  1. type the following command and see the result:

make –f main2.make

Homework Answers

Answer #1

Result of program 1

ayush@ayush:~$ ./reverse
reverse("cat")=tac
reverse("noon")=noon


Result of program 2

ayush@ayush:~$ ./main1
reverse("cat")=tac
reverse("noon")=noon


Result of Program3

-

After modification

Result of make commands

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
please use linux/unix command terminal to complete, step 1 1-create a new directory named by inlab4...
please use linux/unix command terminal to complete, step 1 1-create a new directory named by inlab4 enter directory inlab4 create a new file named by reverse.c with the following contents and then close the file: /*reverse.c */ #include <stdio.h> 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 */ } reverse(char *before,...
LANGUAGE C The codes below reads another .c or .txt file. Then, it will read the...
LANGUAGE C The codes below reads another .c or .txt file. Then, it will read the contents of every line and store the contents into a string array. Example: .c file that is to be read: #include <stdio.h> int main(){    printf("Hello World");    return ; } _______________(END OF THE FILE)_______________ Therefore, the code will read the contents above and store the contents in every line into an array, such that.... array[0] = "#include <stdio.h>\n" array[1] = "\n" array[2] ="int...
Please provide answer in the format that I provided, thank you Write a program that prompts...
Please provide answer in the format that I provided, thank you Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total 52 case sensitive) and five special characters (‘.’, ‘,’, ‘:’, ‘;’ and ‘!’) in all the .txt files under a given directory. The program should include a header count.h, alphabetcount.c to count the frequency of alphabet letters; and specialcharcount.c to count the frequency of special characters. Please only add code to where it says //ADDCODEHERE and keep function names the same. I have also...
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 extern char **environ;    5 void output(char *a[], char...
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 extern char **environ;    5 void output(char *a[], char *b[]) { 6 int c = atoi(a[0]); 7 for (int i = 0; i < c && b[i]; ++i) { 8 printf("%s", b[i]+2); 9 } 10 } 11 12 void main(int argc, char *argv[]) { 13      14 switch (argc) { 15 case 1: 16 for (int i = 0; environ[i]; ++i) {    17 printf("%s\n", environ[i]); 18 } 19 break; 20 default: 21 output(argv +...
use c language only to solve this porblem -------------------------- Have the function StringChallenge(str) take the str...
use c language only to solve this porblem -------------------------- Have the function StringChallenge(str) take the str string parameter being passed and return the number of words the string contains (e.g. "Never eat shredded wheat or cake" would return 6). Words will be separated by single spaces. Examples Input: "Hello World" Output: 2 Input: "one 22 three" Output: 3 you have the following code what edits can you do #include <stdio.h> #include <string.h> void StringChallenge(char str[]) {      // code goes...
Using the C programming language implement Heapsort in the manner described in class. Here is some...
Using the C programming language implement Heapsort in the manner described in class. Here is some example code to use as a guideline. Remember, you need only implement the sort algorithm, both the comparison and main functions have been provided. /* * * after splitting this file into the five source files: * * srt.h, main.c, srtbubb.c, srtinsr.c, srtmerg.c * * compile using the command: * * gcc -std=c99 -DRAND -DPRNT -DTYPE=(float | double) -D(BUBB | HEAP | INSR |...
Consider the C program (twoupdate) to demonstrate race condition. In this assignment, we will implement Peterson's...
Consider the C program (twoupdate) to demonstrate race condition. In this assignment, we will implement Peterson's algorithm to ensure mutual exclusion in the respective critical sections of the two processes, and thereby eliminate the race condition. In order to implement Peterson's Algorithm, the two processes should share a boolean array calledflagwith two components and an integer variable called turn, all initialized suitably. We will create and access these shared variables using UNIX system calls relating to shared memory – shmget,...
Implement and demonstrate a disk-based buffer pool class based on the LRU buffer pool replacement strategy....
Implement and demonstrate a disk-based buffer pool class based on the LRU buffer pool replacement strategy. Disk blocks are numbered consecutively from the beginning of the file with the first block numbered as 0. Assume that blocks are 4096 bytes in size. Use the supplied C++ files to implement your LRU Buffer Pool based on the instructions below. • Implement a BufferBlock class using the supplied BufferBlockADT.h o Your Buffer Block must inherit BufferBlockADT or you will not get credit...
Please answer the following C question: Read the following files called array-utils5A.c and array-utils5A.h. Build an...
Please answer the following C question: Read the following files called array-utils5A.c and array-utils5A.h. Build an executable with gcc -Wall -DUNIT_TESTS=1 array-utils5A.c The definitions for is_reverse_sorted and all_different are both defective. Rewrite the definitions so that they are correct. The definition for is_alternating is missing. Write a correct definition for that function, and add unit tests for it, using the unit tests for is_reverse_sorted and all_different as models. Please explain the logic errors present in in the definition of is_reverse_sorted...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT