You are given a hw04c file which contains a partially comple
Solution
This question has 6 sub parts to be coded. Not sure which sort was used in hw03. Just implemented bubble sort. But not sure of using pointers only . pls check that fuction sortStrings(). Rest of the 5 subquestions have been answered by making reqired code changes.
#include <stdio.h>
 #include <string.h>
 // Read before you start:
 // Do not modify any part of this program that you are given. Doing so may cause you to fail automated test cases.
 // You are given a partially complete program. Your job is to complete the functions in order for this program to work successfully.
 // You should complete this homework assignment using Microsoft Visual Studios 2013 (or a later version).
 // All instructions are given above the required functions, please read them and follow them carefully.
 // If you modify the function return types or parameters, you will fail the automated test cases.
 // You can assume that all inputs are valid. Ex: If prompted for a char, the input will be a char.
// Global Macro Values
 #define NUM_STRINGS 5
 #define STRING_LENGTH 32
// Forward Declarations
void frequency(char[NUM_STRINGS][STRING_LENGTH],char);
 void remove_Number(char[NUM_STRINGS][STRING_LENGTH]);
 void swapStrings(char[STRING_LENGTH], char[STRING_LENGTH]);
 void sortStrings(char[NUM_STRINGS][STRING_LENGTH]);
 void printStrings(char[NUM_STRINGS][STRING_LENGTH]);
 int alpha_Counter(char[STRING_LENGTH]);
 int isAPalindrome(char[STRING_LENGTH]);
 void addLetter(char[STRING_LENGTH], char, int);
// Problem 1: frequency (5 points)
 // Rewrite this function to perform the same task as in hw03, using only pointer operations.
 // You must use pointer operations only. If you use array operations, you will recieve no credit for this part.
 // You may use the code you submitted for hw03 or you may use the solution code for hw03.
 // Traverse the 2D array of characters variable \'strings\' and check the frequency of a particular letter or a search_alphabetin a string.
 // In order to check the frequency, first you need to read the search_alphabet from the user.
 // If the string is \"hello\" and the search_alphabet is l, the code will count the number of \'l\'s in hello.
 // The output of the function for the above mentioned case will be 2.
 //append that frequency value at the end of the string
 //for hello the new string will be hello2
void frequency(char strings[NUM_STRINGS][STRING_LENGTH],char search_alphabet)
 {
    int i,count;
    char *p,*q;
    char cstr[5];
    for(i=0;i<NUM_STRINGS;i++)
    {
        //initialize the counter to zero
        count=0;
        //get the address of each string
        p=strings[i];
       //while the contents of the pointer is not end of string
        while(*p!=\'\\0\')
        {
            if(*p==search_alphabet)
                count++;
            p++;
        }
       
        //convert the count to string
        sprintf(cstr,\"%d\",count);
        q=cstr;
        //already we are at the end of string. just append the count string to it and terminate it
        while(*q!=\'\\0\')
        {
           *p=*q;
            p++;
            q++;
        }
       //put the string terminator at the the end
        *p=\'\\0\';
       
    }
}
// Problem 2: remove_vowel (5 points)
 // Rewrite this function to perform the same task as in hw03, using only pointer operations.
 // You must use pointer operations only. If you use array operations, you will recieve no credit for this part.
 // You may use the code you submitted for hw03 or you may use the solution code for hw03.
 //Traverse the 2D array of characters variable \'strings\' and remove all vowels from the string.
 // In order to remove all vowel characters, you need to check each letter of the string and decide whether its is a vowel. If so then remove it. If not then check the next character.
 // If the string is \"hello\", your result will be hll.
 //print the new string without vowel using problem 6.
void remove_vowel(char strings[NUM_STRINGS][STRING_LENGTH])
 {
    int i;
    char *p,*q;
   for(i=0;i<NUM_STRINGS;i++)
    {
        //get the address of each string
        p=q=strings[i];
       //while the contents of the pointer is not end of string
        while(*p!=\'\\0\')
        {
            //check if current character is lower and uppercase vowel
            if(*p==\'a\' || *p==\'e\' || *p==\'i\' || *p==\'o\' || *p==\'u\' ||
                *p==\'A\' || *p==\'E\' || *p==\'I\' || *p==\'O\' || *p==\'U\')
            {
                //skip to next character          
                p++;
                   
            }  
            else
            {
           
                //keep copying characters which are needed to be preserved
                *q=*p;
                q++;
                p++;
            }
           
        }
       
        //put the string terminator at the end
        *q=\'\\0\';
}
}
void swapStrings(char string1[STRING_LENGTH], char string2[STRING_LENGTH])
 {
 char temp[STRING_LENGTH];
 strcpy(temp, string1);
 strcpy(string1, string2);
 strcpy(string2, temp);
 }
// Problem 3: sortStrings (10 points)
 // Rewrite this function to perform the same task as in hw03, using only pointer operations.
 // You must use pointer operations only. If you use array operations, you will recieve no credit for this part.
 // You can use the swapStrings() function if you\'d like, but are not required to do so.
 // You may use the code you submitted for hw03 or you may use the solution code for hw03.
 //
 // Sort the 5 strings contained in the 2D character array parameter labeled \"strings\".
 // Sort the strings based on their ASCII character value (use strcmp to compare strings).
 // See the output provided in the word document for example input and output.
 void sortStrings(char strings[NUM_STRINGS][STRING_LENGTH])
 {
    int i,j;
    //a simple bubble sort
    for(i=0;i<NUM_STRINGS;i++)
    {
        for( j=i+1;j<NUM_STRINGS;j++)
            if(strcmp(strings[j],strings[i])<0)
                swapStrings(strings[i],strings[j]);
    }
}
void printStrings(char strings[NUM_STRINGS][STRING_LENGTH])
 {
 int i;
 for (i = 0; i < NUM_STRINGS; i++)
 {
 printf(\"%s\ \", strings[i]);
 }
 }
// Problem 4: vowelCounter (10 points)
 // This function accepts an array of characters and returns the number of alphabets in that string (an integer).
 // You must use pointer operations only. If you use array operations, you will recieve no credit for this part.
 // you should not count any number or special character within the string
 int alpha_Counter(char string[STRING_LENGTH])
 {
    char *p=string;
    int count=0;
    while(*p!=\'\\0\')
    {
        //check contents of pointer for alphabet range
        if((*p>=\'a\' && *p<=\'z\') || (*p>=\'A\' && *p<=\'Z\'))
            count++;
        p++;  
    }
    return count;
 }
// Problem 5: isAPalindrome (10 points)
 // This function accepts an array of characters and returns an integer.
 // You must use pointer operations only. If you use array operations, you will recieve no credit for this part.
 // This function should return 1 (true) if the parameter \'string\' is a palindrome, or 0 (false) if \'string\' is not a palindrome.
 // A palindrome is a sequence of characters which when reversed, is the same sequence of characters.
 // For this assignment, you can assume that \'string\' will be a single word containing only lowercase letters and no spaces.
 // Example Palindromes: mom, racecar, stats, rotator, deleveled
 int isAPalindrome(char string[STRING_LENGTH])
 {
    char *p,*q;
    p=q=string;
   
    //first take the 2nd pointer to end of the string, while p points to beginning , q points to last character,
    //keep comparing till p reaches string comparator or break if mismatch
    while(*q!=\'\\0\')
        q++;
   
    q--; // come back from string terminator  
   
    while(*p!=\'\\0\')
    {
        if(*p!=*q)
            return 0; //mismatch , return 0 and no need to compare further
        p++;
        q--;//decrease this pointer to move back  
    }
    //this point is reached only when the previous return 0 had not executed. so it means there was a match of all characters
    return 1;
 }
// Problem 6: addLetter (10 points)
 // This function accepts an array of characters as well as a character to be added to the existig string and a position where this new letter is to be added.
 // You must use pointer operations only. If you use array operations, you will recieve no credit for this part.
 // All occurances of the \'letterToBeRemoved\' should be removed from character array \'string\'
 // Example: If string = \"letter\", and letterToAdd = \'a\'; the pos=2 after this function terminates, string should contain \"leatter\"
 void addLetter(char string[STRING_LENGTH], char letterToAdd, int pos)
 {
    //p points to location where new character wiill come
    char *p=string+pos,*q=string;
    while(*q!=\'\\0\')
        q++;
       
    q++; //new increased length will be beyound null terminator
   
    while(q!=p)
    {
        *q=*(q-1);
        q--;
    }
    *q=letterToAdd;
 }
 // You should study and understand how this main function works.
 // Do not modify it in any way, there is no implementation needed here.
 void main()
 {
 int selection,i;
 char input[STRING_LENGTH];
printf(\"Assignment 4: Pointer Operations\ \ \");
 printf(\"Choose one of the following: \ 1. Sorting Strings\ 2. Alphabet counter\ 3. Palindrome\ 4. Letter Addition\ \ \");
 scanf(\"%d\", &selection); // store integer
 getchar(); // consume newline char
if (selection == 1)
 {
 char strings[NUM_STRINGS][STRING_LENGTH]; // will store 5 strings each with a max length of 32
 char search_alphabet;
for (i = 0; i < NUM_STRINGS; i++)
 {
 printf(\"\ Enter the next String: \"); // prompt for string
 fgets(input, sizeof(input), stdin); // store input string
 input[strlen(input) - 1] = \'\\0\'; // convert trailing \'\ \' char to \'\\0\' (null terminator)
 strcpy(strings[i], input); // copy input to 2D strings array
 }
 printf(\"Enter a character for checking its frequency: \"); // prompt for integer
 scanf(\"%c\", &search_alphabet); // store integer
 frequency(strings, search_alphabet);
 remove_vowel(strings);
 printf(\"\ The strings after vowel removal:\ \");
 printStrings(strings);
 sortStrings(strings);
 printf(\"\ Sorted Strings:\ \");
 printStrings(strings);
}
 else if (selection == 2)
 {
 printf(\"\ Enter a String: \"); // prompt for string
 fgets(input, sizeof(input), stdin); // store input string
 input[strlen(input) - 1] = \'\\0\'; // convert trailing \'\ \' char to \'\\0\' (null terminator)
int numAlpha = alpha_Counter(input);
printf(\"\ There are %d alphabets in \\\"%s\\\"\", numAlpha, input);
 }
 else if (selection == 3)
 {
 printf(\"\ Enter a String: \"); // prompt for string
 fgets(input, sizeof(input), stdin); // store input string
 input[strlen(input) - 1] = \'\\0\'; // convert trailing \'\ \' char to \'\\0\' (null terminator)
int isPalindrome = isAPalindrome(input);
if (isPalindrome)
 printf(\"\ The string \\\"%s\\\" is a palindrome\", input);
 else
 printf(\"\ The string \\\"%s\\\" is not a palindrome\", input);
 }
 else if (selection == 4)
 {
 printf(\"\ Enter a String: \"); // prompt for string
 fgets(input, sizeof(input), stdin); // store input string
 input[strlen(input) - 1] = \'\\0\'; // convert trailing \'\ \' char to \'\\0\' (null terminator)
char letterToAdd;
 int pos;
 printf(\"\ Enter a letter to be added: \"); // prompt for char
 scanf(\" %c\", &letterToAdd); // store input char
 printf(\"\ Enter the array position for adding the letter:\");
 scanf(\"%d\",&pos);
 addLetter(input, letterToAdd, pos);
printf(\"\ Result: %s\", input);
 }
 else
 {
 printf(\"Program terminating...\");
 }
 }






