84.9k views
3 votes
Using the C language, write a function that accepts two parameters: a string of characters and a single character. The function shall return a new string where the instances of that character receive their inverse capitalization. Thus, when provided with the character ā€™eā€™ and the string "Eevee", the function shall return a new string "EEvEE". Using the function with the string "Eevee" and the character ā€™Eā€™ shall produce "eevee".

User Jeremy T
by
3.1k points

1 Answer

4 votes

Answer:

#include <stdio.h>

void interchangeCase(char phrase[],char c){

for(int i=0;phrase[i]!='\0';i++){

if(phrase[i]==c){

if(phrase[i]>='A' && phrase[i]<='Z')

phrase[i]+=32;

else

phrase[i]-=32;

}

}

}

int main(){

char c1[]="Eevee";

interchangeCase(c1,'e');

printf("%s\\",c1);

char c2[]="Eevee";

interchangeCase(c2,'E');

printf("%s\\",c2);

}

Step-by-step explanation:

  • Create a function called interchangeCase that takes the phrase and c as parameters.
  • Run a for loop that runs until the end of phrase and check whether the selected character is found or not using an if statement.
  • If the character is upper-case alphabet, change it to lower-case alphabet and otherwise do the vice versa.
  • Inside the main function, test the program and display the results.
User Rigon
by
3.4k points