c++ - invalid conversion from `const char*' to `char*' -


#include <stdio.h> #include <string.h> #include <conio.h> #define size 20  int main( void ) {     int n; //number of characters compared     char s1[ size ], s2[ size ];     char *results_word;      printf( "enter 2 strings: " );     gets( s1 );     gets( s2 );     printf( "\nenter number of characters compared: " );     scanf( "%d", &n ); 

the problem starts here

    results_word =                   strncmp( s1, s2, n ) > 0 ? " greater " :                   strncmp( s1, s2, n ) == 0 ? " equal " : " smaller " ;      printf( "\n%sis%s%s", s1, results_word, s2 );      getche();     return 0; }//end function main 

so why doesn't result_word corresponding string ?

the c++ error message getting says all:

invalid conversion `const char*' `char*'

you trying assign constant "<literal>" non constant results_word.

change

char *results_word; 

to

const char *results_word; 

and work.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -