【发布时间】:2014-10-03 23:04:42
【问题描述】:
对于下面的代码,如果我输入数字 4 并且 will、ed、bob、bill,我希望输入为 ryan。基本上输出是名称中不是输入之一的那个。它应该是唯一的名字。
但我的代码没有得到任何输出。它确实编译。 谁能帮我解决这个问题?非常感谢您的帮助。提前致谢。
#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;
}
【问题讨论】: