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...
USE C programming (pls label which file is libcipher.h and libcipher.c) Q4) A shift cipher is...
USE C programming (pls label which file is libcipher.h and libcipher.c) Q4) A shift cipher is one of the simplest encryption techniques in the field of cryptography. It is a cipher in which each letter in a plain text message is replaced by a letter some fixed number of positions up the alphabet (i.e., by right shifting the alphabetic characters in the plain text message). For example, with a right shift of 2, ’A’ is replaced by ’C’, ’B’ is...
C CODE PLZ! Need all TO DO sections finished thanks #include <stdio.h> int main(int argc, char...
C CODE PLZ! Need all TO DO sections finished thanks #include <stdio.h> int main(int argc, char **argv) { const int BUF_LEN = 128; char str[BUF_LEN]; int i; char c; int is_binary; int d, n; /* Get the user to enter a string */ printf("Please enter a string made of 0s and 1s, finishing the entry by pressing Enter.\n"); for (i=0; i<BUF_LEN-1; i++) { scanf("%c", &c); if (c == '\n') { break; } str[i] = c; } str[i] = '\0'; /*...
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...
Run Using Kali Linux....Create a source code file named "Lab1.c". The code is as follows. A...
Run Using Kali Linux....Create a source code file named "Lab1.c". The code is as follows. A child is created and prints a message five times. The original process (parent) prints a message only three times. How would this code look on the compiler if you could please post the code and the compiler results. Need Reference Thank You #include <sys/types.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> int main() { pid_t pid; char *message; int n; printf("fork program starting\n"); pid =...
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 |...