For my code below, if i type number four and will, ed, bob, bill, i want the input to be ryan. basically the output to be whichever that is not one of the inputs among the names. And it should be the one and only name always.
But I'm not getting any output on my code. It does compile though. Could anyone help me out with this? highly appreciate the help. thanks in advance.
#include <stdio.h>
#include <string.h>
int main(void)
{
int input_num=0;
int isWill = 0;
int isBob = 0;
int isBill = 0;
int isRyan = 0;
int isEd = 0;
int i=0;
scanf("%d", input_num);
printf("%d", input_num);
for(i;i<input_num;i++)
{
char tmp[1000000];
scanf("%s", tmp);
if( strcmp( tmp, "Will" ) == 0 )
isWill = 1;
else if( strcmp( tmp, "Bob" ) == 0 )
isBob = 1;
else if( strcmp( tmp, "Bill" ) == 0 )
isBill = 1;
else if( strcmp( tmp, "Ryan" ) == 0 )
isRyan = 1;
else if( strcmp( tmp, "Ed" ) == 0 )
isEd = 1;
}
//end of input
char *colors[5];
colors[0] = "Will";
printf("Will\n");
colors[1] = "Bob";
printf("Bob\n");
colors[2] = "Bill";
printf("Bill\n");
colors[3] = "Ryan";
printf("Ryan\n");
colors[4] = "Ed";
printf("Ed\n");
return 0;
}
some of the errors are:
scanf("%d", input_num);
: it should be scanf("%d", &input_num);
not an error but useless: for(i;i<input_num;i++)
: why there is an i
:it should be for(;i<input_num;i++)
If I understood your problem correctly you want to output the names that wasn't written so everything after the loop is wrong for this question
you should see which one of is_something
is equal to 0 and print it