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

Hello, I am in an intro C language programming class and I have this problem ass

ID: 3805877 • Letter: H

Question

Hello,

I am in an intro C language programming class and I have this problem assignment. I am completely stumped.

Thank you.

String Utilities (string utils.c) For this program you will implement the following utility functions to test your mastery of C strings.

void removeBlanks(char *src, char *dest);

void replaceChar(char *src, char oldChar, char newChar);

char *flipCase(const char *src);

Please read the description of these functions carefully. In the removeBlanks function you will implement a routine that takes a string in as src and outputs the same string into dest but removing any blank space character encountered. For example, if the src is “Hel lo Wor ld!”, this function should return the value “HelloWorld!” via the dest pointer .

In the replaceChar function your function should operate much like a find and replace operation in a word processor works, meaning that the function will replace any instance of the character oldChar and replace it with the character newChar. For example, for a src string “Hel lo Wor ld”, if oldChar is ‘o’ and newChar is ‘e’, then src is modified as “Hel le Were ld!”.

In the flipCase function the function turns each lowercase character into an uppercase character and each uppercase character into a lowercase character. For example, if the src string is “GNU Image Processing Tool-Kit”, then this function should return a string “gnu iMAGE pROCESSING tOOL-kIT”.

In your main function, you should prompt the user for a string to use for the first two functions, and a string to use for the third function. The user should be allowed to enter any string including ones with white spaces as input. You should also prompt the user for a character to replace and a replacement character for the flip case function. You may assume that any input string will be at maximum 100 characters.

NOTE:

Functions must match all calls and variables from above perfectly.

The third function must have a seperate input string.

I have included a program demo below for help.

Enter string for remove blanks and replace char function functions: Hello Wor ld! Enter string for flip case function GNU Image Processing Tool-Kit Enter character to replace Enter replacement character 1. remove Blanks Remove all blanks in Hel lo Wor ld! ls: Hello World 2. replace Char Remove all 'o's in Hel lo wor ld! with 'e' s is: Hel le Wer ld! 3 flip Case Original string is GNU Image Processing Tool-Kit Flipped case string is gnu iMAGE pROCESSING tOOL-k IT

Explanation / Answer


// C code
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

void removeBlanks(char *src, char *dest);
void replaceChar(char *src, char oldChar, char newChar);
char *flipCase(const char *src);

int main()
{
char str1[100];
char str2[100];
char str3[100];
  
char des[100];
char* strAfterFlippig;
char oldChar;
char newChar;
  
printf("Enter string for remove blanks and replace char function functions:");
fgets(str1, 100, stdin);
removeBlanks(str1, des);
printf("String after removing blanks is: %s ", des);
  
printf("Enter string for flip case function:");
fgets(str2, 100, stdin);
strAfterFlippig = flipCase(str2);
printf("Stirng after flip case %s ", strAfterFlippig);
  
printf("Enter string for Replacement:");
fgets(str3, 100, stdin);
printf("Enter replacement character:");
char temp[5];
scanf("%s",temp);
oldChar = temp[0];
printf("Enter new character to replace:");
scanf("%s",temp);
newChar = temp[0];
replaceChar(str3,oldChar,newChar);
printf("Stirng after Replacement %s ", str3);
return 0;
}

void removeBlanks(char *src, char *dest) {
int length = strlen(src);
int i = 0;
int j = 0;
for(i = 0; i < length; i++) {
if(src[i] != ' ') {
dest[j] = src[i];
j++;
}
}
dest[j] = '';
}

void replaceChar(char *src, char oldChar, char newChar) {
int length = strlen(src);
int i;
for(i = 0; i < length; i++) {
if(src[i] == oldChar) { //Compare
src[i] = newChar; //Assign
}
}
}

char *flipCase(const char *src) {
  
char *tempStr = (char *) malloc(sizeof(char) * (strlen(src)+1));
//Copy source to tempStr
strcpy(tempStr, src);
int i;
//Check if case if lower or upper
for(i = 0; i < strlen(src); i++) {
if(isupper(tempStr[i])) {
tempStr[i] = tolower(tempStr[i]);
} else if(islower(tempStr[i])) {
tempStr[i] = toupper(tempStr[i]);
} else {
tempStr[i] = tempStr[i];
}
}
tempStr[i] = '';
return tempStr;
}


/*
output:

Enter string for remove blanks and replace char function functions:Hel lo World!
String after removing blanks is: HelloWorld!

Enter string for flip case function:GNU Image Processing Tool-Kit
Stirng after flip case gnu iMAGE pROCESSING tOOL-kIT

Enter string for Replacement:Hel lo World!
Enter replacement character:o
Enter new character to replace:w
Stirng after Replacement Hel lw Wwrld!

*/

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