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:
/*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;
}
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”
/* reverse.h */
reverse(char *before, char *after); /* declare but do not define this function */
/*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;
}
/*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 */
}
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:
cp –r inlab4 inlab6
/* PALINDROME.H */
int palindrome(); /* Declare but do not define */
/* 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 */
}
/* main2.c */
#include <stdio.h>
#include "palindrome.h"
/*****************************************************/
main()
{
printf("palindrome (\"cat\") = %d\n", palindrome("cat"));
printf("palindrome (\"noon\") = %d\n", palindrome("noon"));
}
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
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
make –f main1.make
make –f main2.make
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
Get Answers For Free
Most questions answered within 1 hours.