0
I wrote a code that excluded the similar term in both strings, but it does not print the result of the text by taking the second term, it only removes the first term from the first string.
"Create a program that receives a phrase and a term. If term is present in the sentence, remove it and print the sentence modified, otherwise, display "Term not found in phrase". Consider the maximum string size of 200."
#include <stdio.h>
#include <string.h>
int main()
{
char texto[200];
char word[10];
int l1, ind, tam, j = 0, i, c = 0, r;
scanf("%s", texto);
gets(texto);
scanf("%s", word);
tam = strlen(texto);
for (i = 0; i < l1; i++) {
r = strcmp(texto, word);
j = j + 1;
}
if ((texto != '\0') && (word != '\0')) {
for (i = 0; i < l1; i++) {
ind = (strlen(texto)-1) / j;
j = j + 1;
}
printf("%s\n", texto);
} else
{
printf("Termo não encontrado na frase.\n");
}
return 0;
}
Why do you have
scanf("%s",texto);
andgets(texto);
? just having thegets(texto);
With the scanf reading the text, it will only read as far as space exists, i.e., read only the first word of the text. Use gets– IanMoone
@Ianmoone - the recommended is to use fgets, not gets, which is very easy to give problems because it can overwrite the memory outside the reading area.
– zentrunix
I edited the code to put spaces, it makes it easier to read...in the "real world" nobody uses the type of C code that appears here in the OS, all glued and without spaces...another problem of this code (and the absolute majority of C codes that appears here) is the absolute absence of comments explaining the code...who can’t explain in the code what’s going on, so generally you don’t know what’s going on...
– zentrunix