Question

In: Computer Science

Write a C program for the recursive algorithm that removes all occurrences of a specific character...

Write a C program for the recursive algorithm that removes all occurrences of a specific character from a string. (please comment the code)

Solutions

Expert Solution

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

void deletechar(char *s,char c)
{
   static int i=0,k=0; // for not creating again
if(!s[i])// if s[i] become null return
{
  
   return;
   }
   else
   {
      s[i]=s[i+k];// store s[i+k] into s[i]
    if(s[i]==c)// check if s[i] equal to target character
    {
       k++;//increase k to next index
       i--;// decrease i to previous index
   }
   i++;// if not the target character increase i
   deletechar(s,c);// again call deletechar till s[i] reaches null   
   }

}

int main()
{

char s[1000],c; // create string and variable c
printf("Enter the string : ");
gets(s); // get string
printf("Enter character: ");
c=getchar(); // get character to be deleted
deletechar(s,c); // call function
printf("string after removing all occurance of character :'%c'\n",c);
printf("%s",s); // print string after removing character
   return 0;
  
}
/* PLEASE UPVOTE */


Related Solutions

1) a. Write a C++ program for the recursive algorithm that removes all occurrences of a...
1) a. Write a C++ program for the recursive algorithm that removes all occurrences of a specific character from a string b. Write the pseudocode for the program.
Create a program in C++ implementing the LinkedStack 7. Write a client that removes all negative...
Create a program in C++ implementing the LinkedStack 7. Write a client that removes all negative numbers from a stack of int objects. If the original stack contained the integers 30, –15, 20, –25 (top of stack), the new stack should contain the integers 30, 20.
write a c++ member function that removes the first instance of a specific element in a...
write a c++ member function that removes the first instance of a specific element in a linked list and then return the size of the list after the removal whether it was successful or not.
write a c++ member function that removes the FIRST OCCURENCE of a SPECIFIC ELEMENT in a...
write a c++ member function that removes the FIRST OCCURENCE of a SPECIFIC ELEMENT in a linked list. After attemtped removal return the SIZE of the linked lost whether or not the removal was successful.
Program in C Write a function that takes a string as an argument and removes the...
Program in C Write a function that takes a string as an argument and removes the spaces from the string.
Write a C++ program that uses a de-duplication function that iteratively sanitizes (removes) all consecutive duplicates...
Write a C++ program that uses a de-duplication function that iteratively sanitizes (removes) all consecutive duplicates in a C++ string. Consecutive duplicates are a pair of duplicate English alphabets sitting next to each other in the input string. Example: "AA", "KK", etc., are all consecutive duplicates. This function will internally run as many iterations as needed to remove all consecutive duplicates until there is either no consecutive duplicates left, or the string becomes empty (in which the function returns "Empty"...
Recursion java: 1. Write a recursive algorithm to add all the elements of an array of...
Recursion java: 1. Write a recursive algorithm to add all the elements of an array of n elements 2. Write a recursive algorithm to get the minimum element of an array of n elements 3. Write a recursive algorithm to add the corresponding elements of two arrays (A and B) of n elements. Store the results in a third array C .4. Write a recursive algorithm to get the maximum element of a binary tree 5. Write a recursive algorithm...
Code in C# please. Write a program that will use the greedy algorithm. This program will...
Code in C# please. Write a program that will use the greedy algorithm. This program will ask a user to enter the cost of an item. This program will ask the user to enter the amount the user is paying. This program will return the change after subtracting the item cost by the amount paid. Using the greedy algorithm, the code should check for the type of bill. Example: Cost of item is $15.50 User pays a $20 bill $20...
Write a C program that will read a character string and then encrypt the string based...
Write a C program that will read a character string and then encrypt the string based on one of the 3 different encryption methods. The type of encryption is to be selected by the user. Encryption method 1: Swapping by position. Characters in the array are swapped with the opposite characters based on their position in the string. Example: Input string – apple. Encrypted string – elppa Method: The first character ‘a’ and the last character ‘e’ – swap their...
Write a basic C++ program with function, whose input is a character and a string, and...
Write a basic C++ program with function, whose input is a character and a string, and whose output indicates the number of times the character appears in the string. Ex: If the input is: n Monday the output is: 1 Ex: If the input is: z Today is Monday the output is: 0 Ex: If the input is: n It's a sunny day the output is: 2 Case matters. n is different than N. Ex: If the input is: n...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT