some fundamental coding errors needs to be addressed here along with logical flaw.
before we proceed lets format to 4 spaces
int main()
{
/* Lets simplify these two statements */
// char ce[] = {"ceil"};
// char fl[] = {"floor"};
char *ce = "ceil";
char *fl = "floor";
/* format this into one line .. */
printf("hello choose one ceil or floor : \n" );
/* instead of accepting two values, you may want to accept one
as per the question asked above the input is either floor or ceil */
/* lets declare a buffer to store the choice */
char choice[255];
/* scan choice */
scanf("%s", choice );
/* Below wont work, ceil and floor are already char *
&ceil and &floor will make them char ** so this wont work */
// scanf("%s", &ceil);
// scanf("%s", &floor);
/* some commentary on this code snippet below */
/* 1. ce is an address, a positive integer hence the if statement
will always evaluates to true
2. else has an expression else() that is wrong syntax .
3. else ending with ; another wrong syntax.
lets say the below snippet wont compile
if ( ce )
testdovom();
else ( fl );
testaval();
*/
/* instead we use strcmp function from string.h
and check if choice is "floor" or "ceil" */
if( strcmp(choice, ce) == 0 )
{
testdovom();
}
else if( strcmp(choice, fl) == 0 )
{
testaval();
}
else
{
/* we've got something we donot handle */
printf("Invalid input");
}
return 0;
}
3
solved how to create input like answer