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...
The code is in C programming language pls convert it into python. Thanks. Program --> #include...
The code is in C programming language pls convert it into python. Thanks. Program --> #include <stdio.h> #include <stdlib.h> void main() { //declare variables FILE *fileptr; char filename[15]; char charRead; char filedata[200],searchString[50]; int i=0,j=0,countNoOfWord=0,count=0; //enter the filename to be opened printf("Enter the filename to be opened \n"); scanf("%s", filename); /* open the file for reading */ fileptr = fopen(filename, "r"); //check file exit if (fileptr == NULL) { printf("Cannot open file \n"); exit(0); } charRead = fgetc(fileptr); //read the string...
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...
A program is already given to you.  There are five problems in this skeleton version of the...
A program is already given to you.  There are five problems in this skeleton version of the program, each is 10 points. All you got to do is complete the missing code in each function. What the function does is clearly stated in the name of the function.   // ASSIGNMENT ON FUNCTIONS #include <stdio.h> // Problem 1: Compile with gcc func_assignment.c -Wall // There are some warnings because there is a mismatch between // data type passed and defined. // Find...
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...
I am to create three different versions of the following C program code below that implements...
I am to create three different versions of the following C program code below that implements the conversion of unsigned binary numbers into decimal (Base 2 to Base 10 conversion). Version 1: Complete the C program ”bin2dec ver1.c” that implements binary to decimal conversion. The maximum number of binary bits is 32. The program is made of the functions ”unsigned binary to decimal(const char *str)”and ”main”. The parameter ”str” passed to this function points to a C string comprising only...
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...
If you cant answer this please dont waste my question. thank you. This cryptographic program run...
If you cant answer this please dont waste my question. thank you. This cryptographic program run and produce text screen output. You are to create a GUI that uses the program. Your program (GUI) must allow a user to input of a message to be coded. It must also have an area to show the plaintext, the ciphertext, and the decrypted text. If required by your choice of cryptographic method, the user should have an area to input a key....
C++ Pig Latin Lab This assignment uses pointers to perform something done often in computer applications:...
C++ Pig Latin Lab This assignment uses pointers to perform something done often in computer applications: the parsing of text to find “words” (i.e., strings delineated by some delimiter). Write a program that encodes English language phrases into Pig Latin. Pig Latin is a form of coded language often used for amusement. Many variations exist in the methods used to form Pig Latin phrases. Use the following algorithm: to form a Pig Latin phrase from an English language phrase, tokenize...