Create a UNIX makefile for the following C program: //convert.c char toUpper(cha
ID: 3730299 • Letter: C
Question
Create a UNIX makefile for the following C program:
//convert.c
char toUpper(char c){
if(c>='a' && c<='z')
return c-32;
return c;
}
//converting sentance to upper
void convertSentence(char *sentence){
int i=0;
while(sentence[i]!=''){
//convert to upper for each character
sentence[i] = toUpper(sentence[i]);
i++;
}
}
//converting all sentences into uppercase
void convertAll(char **sentenceList, int numOfSentences){
int i=0;
while(i<numOfSentences){
//calling convertsentence function to conver uppercase
convertSentence(sentenceList[i]);
i++;
}
}
sentences.c
#include<stdio.h>
#include<stdlib.h>
#include "convert.c"
int main(){
//declaring character array
char **mySentences;
int noOfSentences;
//taking how many sentences that user taking
printf("Welcome. Please tell me how many sentences you wish to enter (no more than 10): ");
scanf("%d", &noOfSentences);
printf("You entered %d. Please enter your sentences one at a time. A sentence can only store 100 characters. ", noOfSentences);
//allocating dynamic memory for no of sentances
mySentences = (char **)malloc(noOfSentences*sizeof(char *));
int i;
for(i=0;i<noOfSentences; i++){
//allocating dynamic memory for sentence length with default 100
printf("Enter sentence #%d: ", i+1);
mySentences[i] = (char *)malloc(100*sizeof(char));
scanf(" %[^ ]s", mySentences[i]);
}
//converting all sentences into upper case
convertAll(mySentences, noOfSentences);
//printing converted upper case sentences
printf("Your Converted Sentences are: ");
int chars = 0, withOutSpaces = 0;
for(i=0;i<noOfSentences; i++){
int len = 0;
while(mySentences[i][len]!=''){
if(mySentences[i][len]!=' ')
withOutSpaces++;
len++;
chars++;
}
printf("%s ", mySentences[i]);
}
printf(" There are %d Characters, or %d, not including the whitespace", chars, withOutSpaces);
printf(" End Program");
printf(" Press any key to continue . . . ");
getchar();
return 0;
}
[rkv-sdc@localhost 888320181$ gcc -Wall sentences. [rkv-sdc@localhost 8032018]s ·/a.out Welcone. Please tell ne how nany sentences you wish to enter (no nore than 10): 4 You entered 4. Please enter your sentences one at a tine. A sentence can only store 100 characters. Enter sentence #1: Hy nane is beth. Enter sentence #2 : Hello. Enter sentence #3: Goodbye 123 Enter sentence #4: I'm done Your Converted Sentences are: HY NAHE IS BETH HELLO GOODBYE 123 I'H DONE There are 41 Characters, or 36, not including the whitespace End Progran Press any key to continue .. . [rkv-sdc@localhost 080320181$Explanation / Answer
Below two lines are enough to make UNIX makefile for your c program. Create a file name called makefile and copy the below two lines into it.
sentences:
gcc -Wall -o sentences sentences.c
Note:
There is a TAB space required in starting of the second line.
The general syntax of a Makefile.
target [target...] : [dependent ....]
[ command ...]
Arguments in brackets are optional. Note the tab space required before each command.
In our makefile target is sentences, no dependent and command is gcc -Wall -o sentences sentences.c