I'm having trouble calling the function more than one time in my C program. The gist of the assignment is to replace the whitespaces in a sentence inputted from the user and replace it with a different character. For some reason, the program will call the same first function multiple times. I tried putting the strlen(x) in a variable inside my function, but I'm not very well versed in the C language, so I decided to leave it out of my code.
#include <string.h>
void display(char x[], char y);
void main(){
//Do not change this function
char a[100];
printf("Enter a sentence\n");
gets(a);
display(a, '*'); //To replace every space by *
display(a, '-'); //To replace every space by -
display(a, '+'); //To replace every space by +
}
void display(char x[], char y){
for(char i = 0; i < strlen(x); i++) {
if(x[i] == ' ') {
x[i] = y;
}
}
printf("%s\n", x);
}