4
I can’t make it into the loop using only the char
'Anunciar'
, when you put something in, it starts the loop. What should I do?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
char nome[50], op;
int sexo, passatempo, musica, filme, auto_declara;
printf("Ola, seja bem-vindo ao Colega de Quarto, como voce se chama ? ");
scanf("%[^\n]s", &nome);
printf("O que voce deseja, %s ?\n\n", nome);
printf("---Anunciar---\n\n");
printf("---Procurar---\n\n");
scanf("%s", &op);
do
{
printf("\nFormule seu perfil de acordo com as opcoes abaixo: \n");
printf("\n");
printf("---Sexo---\n");
printf("1 - Masculino\n");
printf("2 - Feminino\n");
scanf("%d", &sexo);
printf("\n");
printf("---Hobby---\n");
printf("1 - Ler\n");
printf("2 - Praticar esportes\n");
printf("3 - Festar\n");
scanf("%d", &passatempo);
printf("\n");
printf("---Gosto Musical---\n");
printf("1 - Rock\n");
printf("2 - Funk\n");
printf("3 - Sertanejo\n");
printf("4 - Rap\n");
scanf("%d", &musica);
printf("\n");
printf("---Tipo de Filme---\n");
printf("1 - Acao\n");
printf("2 - Suspense\n");
printf("3 - Terror\n");
printf("4 - Drama\n");
printf("5 - Comedia\n");
printf("6 - Ficcao Cientifica\n");
scanf("%d", &filme);
printf("\n");
printf("---Voce se autodeclara ?---\n");
printf("1 - Preguicosa\n");
printf("2 - Prestativa\n");
printf("3 - Caseira\n");
printf("4 - Festeira\n");
scanf("%d", &auto_declara);
} while(op == 'Anunciar');
return 0;
}
You declared your op variable to contain a single character but try to read a string into it and then make a comparison in while by mixing a character with a string but using the character delimiter (a single one, between ') and not a string (between "). Also to compare strings you need to use the strcmp function of <string. h> and not the operator ==.
– anonimo