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

Create a new function called SKUDasher()in MyLib.c. Be sure to add the prototype

ID: 3708164 • Letter: C

Question

Create a new function called SKUDasher()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 non dashed SKU and will return the dashed SKU to Code6_xxxxxxxxxx.c to be printed.
case 4 in your menu in Code6_xxxxxxxxxx.c will call SKUDasher() and then print the output. This function must follow the same rules but in reverse for putting the dash back into a SKU. If the input SKU is 1200009, then the output is 12-9.

Explanation / Answer

CODE:

#include <stdio.h>//FROM HEADER

#include <string.h>//FROM HEADER

void SKUConverter(char OutputArray[]) {//ARRAY LIST

   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);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote