Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part 4 using the algorithm below Part 4 Create a new function called skUConverte

ID: 3739179 • Letter: P

Question

Part 4 using the algorithm below

Part 4 Create a new function called skUConverter ) in MyLib.c. Be sure to add the prototype to your MyLib.h. This function will have one parameter that is an array that contains the output from this function. This function will prompt the user for a dashed SKU and will return the full SKU to Code 6 xxxxxxxxxx. c to be printed. case 3 in your menu in Code6 xxxxxxxxxx.c will call sKUConverter (0 and then print the output. void SKUConverter (char OutputArray[]) Put your variables here Prompt the user for a dashed SKU If the entered dashed SRU is greater than 9 character, Then print "the entered dashed 3KU is not valid" and return

Explanation / Answer

#include <stdio.h>
#include <string.h>

void SKUConverter(char OutputArray[]) {
   char InputArray[256];
   char LestSide[10];
   char RightSide[10];
   char FinalSKU[10];
   int countDash = 0;
   int countOther = 0;
   int dashPos = -1;
   int pad;
   int i;

   printf("Enter dashed SKU: ");
   gets(InputArray);

   if (strlen(InputArray) > 9) {
       printf("The entered dashed SRU is not valid ");
       return;
   }

   if (isdigit(InputArray[0]) == 0 || isdigit(InputArray[strlen(InputArray) - 1]) == 0) {
       printf("Dash must be between two numbers ");
       return;
   }

   for(i = 0; i < strlen(InputArray); i++) {
       if (InputArray[i] == '-') {
           countDash ++;
           dashPos = i;
       }
       else if (InputArray[i] < '0' || InputArray[i] > '9') {
           countOther ++;
       }
   }

   if (countOther > 0 || countDash > 1) {
       printf("Input SKU can only contain numbers and one dash ");
       return;
   }
   else if (countDash == 1 && strlen(InputArray) == 7) {
       strcpy(OutputArray, InputArray);
       return;
   }

   else if (countDash == 0) {
       printf("Input SKU must contain a dash ");
       return;
   }

   else if (countDash > 1) {
       printf("Input SKU can contain only one dash ");
       return;
   }

   srecpy(LestSide, InputArray);
   LestSide[dashPos] = '';

   strcpy(RightSide, InputArray + dashPos + 1);

   for (i = 0; i < 3; i++)
       if (LestSide[i] == '') {
           LestSide[i] = '0';
           LestSide[i + 1] = ''
       }
   LestSide [3] = '';

   strcpy(FinalSKU, LestSide);

   pad = strlen(RightSide) - 4;

   if (pad <= 0) {
       RightSide[4] = '';
   }
   else {
       for (i = strlen[RightSide]; i >= 0; i--) {
           RightSide[i + pad] = RightSide[i];
       }
       for (i = 0; i < pad; i++) {
           RightSide[i] = '0';
       }
   }
  
   strcat (FinalSKU, RightSide);
   strcpy(OutputArray, FinalSKU);

}

Here you go champ.... Coded exactly the way it is documented