Question: string_utils.c Program Help Hello, I am writing a program to help demostrate the many functions strings can perform in C language. I currently have this
string_utils.c Program Help
Hello, I am writing a program to help demostrate the many functions strings can perform in C language. I currently have this code below but have one problem while compiling...
//String Utilities BY **
//Made 03-22-2017
#include
void removeBlanks(char *src, char *dest); void replaceChar(char *src, char oldChar, char newChar); char *flipCase(const char *src);
int main(){
char src[100]="default",choice='q',oldChar='q',newChar='q';
printf("Enter the input string: "); fgets(src, 100, stdin);
printf(" 1: Remove Blanks 2: Replace Character 3: FlipCase "); printf(" Enter the choice: "); scanf("%c",&choice);
switch(choice){
case '1':
removeBlanks(src,dest); ----THIS LINE HERE IS LEFT WITH AN ERROR MESSAGE break;
case '2':
printf(" Enter character to replace: "); scanf(" %c", &oldChar);
printf(" Enter replacement character: "); scanf(" %c", &newChar);
replaceChar(src,oldChar,newChar); break;
case '3':
flipCase(src); break;
default: printf(" Wrong choice!! "); break;
} return (1); }
void removeBlanks(char *src, char *dest){ int size = strlen(src); int i,j = 0; for(i = 0; i < size; i++){ if(!isspace(src[i])){ dest[j] = src[i]; j++; } } }
void replaceChar(char *src, char oldChar, char newChar){
char temp[1000]; int j=0,i=0; for(i=0;src[i]!='\0';i++){
if(src[i]!= oldChar) temp[j++]=src[i]; else{ temp[j++]= newChar; } }
temp[j]='\0'; printf("String after replacing %c by %c in %s Is: %s",oldChar,newChar,src,temp);
}
char *flipCase(const char *src){
char *output; output = malloc(strlen(src) + 1);
strcpy(output,src);
int i = 0;
while(output[i] != '\0'){
if(isalpha(src[i])){ if (isupper(src[i])){ output[i]= tolower(src[i]); i++; } else{ if (islower(src[i])){ output[i]=toupper(src[i]); i++; } } } else i++; }
printf(" The original string was: %s The Flipped Case string is: %s", src, output); }
The error message declares that "dest" has no reference as it has not been used before. The functions must remain the same for me to recieve credit.
The program takes a string and can perform one of three tasks:
1) Remove spaces
2) Switch a character
3) Flip case
Thank you very much.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
