Can someone Please help??? You will be using/modifying the files below to make C
ID: 3703994 • Letter: C
Question
Can someone Please help???
You will be using/modifying the files below to make Code 6
MyLib.c
#include <stdio.h>
#include "MyLib.h"
void ConvertDecimalToBinary(int DecimalNum, int BitArray[])
{
int i;
BitArray[7] = DecimalNum;
for (i = 6; i >= 0; i--)
{
BitArray[i] = BitArray[i+1] >> 1;
}
printf(" Decimal %d converts to binary ", DecimalNum);
for (i = 0; i <= 7; i++)
{
BitArray[i] = (BitArray[i] & 1) ? 1 : 0;
}
return;
}
void PrintBinary(int BinaryNumber[])
{
int i;
for (i = 0; i <= 7; i++)
{
printf("%d", BinaryNumber[i]);
}
printf(" ");
}
MyLib.h
#ifndef _MYLIB_H_
#define _MYLIB_H_
void ConvertDecimalToBinary(int DecNum, int BitArray[]);
void PrintBinary(int BinaryNumber[]);
#endif
MakeFile
SRC = Code6_1000074079.c
OBJ = $(SRC:.c=.o)
EXE = $(SRC:.c=.e)
LSRC = MyLib.c
LOBJ = $(LSRC:.c=.o)
LHDR = $(LSRC:.c=.h)
CFLAGS = -g
LIBOBJ = $(LOBJ)
all : $(EXE)
$(EXE): $(OBJ) $(LIBOBJ)
gcc $(CFLAGS) $(OBJ) $(LIBOBJ) -o $(EXE)
$(OBJ) : $(SRC)
gcc -c $(CFLAGS) $(SRC) -o $(OBJ)
$(LOBJ): $(LSRC) $(LHDR)
gcc -c $(CFLAGS) $(LSRC) -o $(LOBJ)
Thanks in advance
Part 1 Create Code6_xxxxxxxxxx.c. This program will be used to exercise the library functions that you will create as part of this assignment. This program will display a menu where each menu item will be one of your library functions which will reside in MyLib.c 1. Convert Decimal to Binary 2. Sentence Cleanup 3. SKU Converter Enter menu choice Code 6_xxxxxxxxxx.c will not contain any of the code for these functions they will only be called and the output will be itch statement to 1t statement in case a entered that is not valid.Explanation / Answer
here is your program : ---------->>>>>>>>
MyLib.c : ---------->>>>>>>>>
#include <stdio.h>
#include<string.h>
#include "MyLib.h"
void ConvertDecimalToBinary(int DecimalNum, int BitArray[])
{
int i;
BitArray[7] = DecimalNum;
for (i = 6; i >= 0; i--)
{
BitArray[i] = BitArray[i+1] >> 1;
}
printf(" Decimal %d converts to binary ", DecimalNum);
for (i = 0; i <= 7; i++)
{
BitArray[i] = (BitArray[i] & 1) ? 1 : 0;
}
return;
}
/*remove this commented part of code as your part 2 says if you want
void PrintBinary(int BinaryNumber[])
{
int i;
for (i = 0; i <= 7; i++)
{
printf("%d", BinaryNumber[i]);
}
printf(" ");
}
*/
void SentenceCleanup(char outputArray[]){
char array[500];
char *token;
char punc[2];
int i,j;
char delim[4] = ".!?";
printf("Enter at least two sentence seperated by one of these delimeters - .!? - ");
printf("(max of 500 characters total) ");
fgets(array,500,stdin);
char *copy = strdup(array);
token = strtok(array,delim);
while(token != NULL){
punc[0] = copy[token-array+strlen(token)];
punc[1] = '';
i = -1;
do{
i++;
}while(token[i] == ' ');
for(j = 0;i<=strlen(token);j++,i++){
token[j] = token[i];
}
i = strlen(token);
do{
i--;
}while(token[i] == ' ');
token[i+1] = '';
if((int)token[0] >= 97){
token[0] = (char)((int)(token[0]) - 32);
}
strcat(outputArray,token);
strcat(outputArray,punc);
strcat(outputArray," ");
token = strtok(NULL,delim);
}
}
MyLib.h : ----------->>>>>>>>>
#ifndef _MYLIB_H_
#define _MYLIB_H_
void ConvertDecimalToBinary(int DecNum, int BitArray[]);
void SentenceCleanup(char outputArray[]);
//void PrintBinary(int BinaryNumber[]);
#endif
c6xxxxxxxx.c : ------------>>>>>>>>>
#include "MyLib.c"
void menu(){
printf(" 1. Convert To Decimal");
printf(" 2. Sentence Clean Up");
printf(" 3. SKU converter");
printf(" 4. Exit");
printf(" Enter Menu Choice : ");
}
void print(int bin[]){
int i;
for(i = 0;i<8;i++){
printf("%d ",bin[i]);
}
printf(" ");
}
int main(){
int BitArray[8];
char arr[500] = "";
int dec = 20;
int ch = 0;
while(ch != 4){
menu();
scanf("%d",&ch);
switch(ch){
case 1:
{
printf(" Enter decimal number : ");
scanf("%d",&dec);
ConvertDecimalToBinary(dec,BitArray);
print(BitArray);
break;
}
case 2:
{
fflush(stdin);
SentenceCleanup(arr);
printf("%s",arr);
break;
}
case 3:
{
break;
}
case 4:break;
default:
printf(" Invalid Choice ");
}
}
return 0;
}