C program, how do you print the word without the character?

0

IcannotprintthewordwithoutthecharacterandIhavenoideahowtoexecutetheending.ifanyonecanhelp

followwhatI'vealreadydone:

#include<stdio.h>#include<string.h>intmain(){charfrase[20],nova[20];charcaracter[1];intx,y;printf("Informe a frase: ") ;
    fgets(frase, sizeof(frase), stdin);
    printf("Informe o Caracter: ");
    gets(caracter);

        for(x=0;x<=strlen(frase);x++)
        if(frase[x]!=caracter)
        nova[y++]=frase[x];

    printf("Frase remontada sem o caracter: %s", nova);

    return 0;
}
    
asked by anonymous 17.12.2017 / 21:00

2 answers

0

I've assumed you want to remove only one character from the sentence, if it's really a word, you'll need to make some changes.

You were using the y variable without initializing it and caracter as an array instead of just char .

Here is the code with the necessary changes:

#include <stdio.h>
#include <string.h>
int main() {
  char frase[20], nova[20];
  char caracter;
  int x, y = 0;
  printf("Informe a frase: ") ;
  fgets(frase, sizeof(frase), stdin);
  printf("Informe o caracter: ");
  caracter = getchar();

  for (x = 0; x <= strlen(frase); x++)
    if (frase[x] != caracter)
      nova[y++] = frase[x];

  printf("Frase remontada sem o caracter: %s", nova);

  return 0;
}
    
17.12.2017 / 23:56
0
#include <stdio.h>
#include <stdlib.h>

int primeiraOcorrencia = 0;
char* f;
char* p;
char* m;
char* copiaF;
char frase[160];
char palavra[80];

int main(int argc, char* argv[])
{
    printf("Frase de entrada: ");
    fgets(frase, 160, stdin);
    printf("\n");
    printf("Palavra a ser retirada: ");
    scanf("%s", palavra);

    f = frase;
    p = palavra;

    primeiraOcorrencia = 1;

    while (*f)
    {
        if (*p != *f && *p != '
#include <stdio.h>
#include <stdlib.h>

int primeiraOcorrencia = 0;
char* f;
char* p;
char* m;
char* copiaF;
char frase[160];
char palavra[80];

int main(int argc, char* argv[])
{
    printf("Frase de entrada: ");
    fgets(frase, 160, stdin);
    printf("\n");
    printf("Palavra a ser retirada: ");
    scanf("%s", palavra);

    f = frase;
    p = palavra;

    primeiraOcorrencia = 1;

    while (*f)
    {
        if (*p != *f && *p != '%pre%')
        {
            primeiraOcorrencia = 1;
            p = palavra;
        }
        else
        {
            if (primeiraOcorrencia)
            {
                m = f;
                primeiraOcorrencia = 0;
            }

            if (!*p++)
            {
                copiaF = f;

                while (*copiaF)
                {
                    *m++ = *copiaF++;
                }
                *m = '%pre%';

                primeiraOcorrencia = 1;
                p = palavra;
            }
        }

        f++;
    }

    printf("Frase final sem a palavra: %s", frase);

    system("pause");
}
') { primeiraOcorrencia = 1; p = palavra; } else { if (primeiraOcorrencia) { m = f; primeiraOcorrencia = 0; } if (!*p++) { copiaF = f; while (*copiaF) { *m++ = *copiaF++; } *m = '%pre%'; primeiraOcorrencia = 1; p = palavra; } } f++; } printf("Frase final sem a palavra: %s", frase); system("pause"); }
    
11.06.2018 / 01:55