C, Print and save character string

1

It's a simple program, I tried it with words instead of words and it worked, but I wanted to play a bit but I do not know how to do it for words, for a letter if it works for me.

This error throws me: warning: multi-character character constant [-Wmultichar] |

#include <stdio.h>

int main(){

char opc[10];

printf("De que color es el cielo?: ");
printf("\nA. Azul");
printf("\nB. Rojo");
printf("\nC. verde");
printf("\nD. morado\n");
scanf("%s", opc);

if(*opc=='azul'){
    printf("El resultado es correcto");
}else{
    printf("El resultado incorrecto");
}

return 0;
}
    
asked by Jenio158 18.10.2017 в 05:54
source

1 answer

0

Complains that the simple-quote ' is used to indicate characters , not strings with more than 1 character.

The strings in C do not compare like this; you have to use the strcmp( ) function:

#include <stdio.h>

int main( void ){
  char opc[10];

  printf( "De que color es el cielo?: " );
  printf( "\nA. Azul" );
  printf( "\nB. Rojo" );
  printf( "\nC. verde" );
  printf( "\nD. morado\n" );
  scanf( "%s", opc );

  if( !strcmp( "azul", opc ) ) {
    printf( "El resultado es correcto" );
  } else {
    printf( "El resultado incorrecto" );
  }

  return 0;
}
    
answered by 18.10.2017 / 06:25
source