0
I have to create a function to make the exchange of some character.
This is the exercise:
1. Build a function that receives a message, its size and a
character and remove all occurrences of that character in the message
putting * in its place. The function should return the total of characters
withdrawn.
And I did the following:
#include <stdio.h>
#include <string.h>
#include <locale.h>
void filtro(char msg[500] ,int tamanho, char c){
setlocale(LC_ALL,"portuguese");
char mensagem[500];
strcpy(mensagem,msg);
int i,r=0;
for (i=0; i<tamanho; i++){
if(mensagem[i]==c){
r++;
mensagem[i] = "*";
}
}
printf("\nMensagem modificada: \n %s", mensagem);
printf("\nCaracteres retirados: %d", r);
}
void main(){
setlocale(LC_ALL,"portuguese");
char msg[500], c;
printf("Escreva uma mensagem de até 500 caracteres\n");
gets(msg);
printf("Informe o caracter a ser removido: ");
scanf("%c", &c);
filtro(msg, strlen(msg), c);
}
But I get the following error message:
[Warning] assignment makes integer from Pointer without a cast
It even detects the letters and makes a switch. But instead of putting '*' it puts the following character:
Perfect! Thanks for the solution and the great explanation!
– Victor Eyer