int main(int argc, char *argv[])
{
int length,i,j;
char *key;
printf("\n\n\n What is the length of key?\n");
scanf("%d",&length);
key=(char*)malloc (length*sizeof(char));
for(i=0;i<length;i++)
{
printf("\n Enter %d. character ...\n",i+1);
scanf("%c",&key[i]);
}
getch();
system("PAUSE");
return 0;
}
当我执行时,它会询问
enter 1.character enter 2. character input here enter 3.char enter 4.char
就这样,它不问奇数。不仅奇数,例如长度为 7,它问 4 个字符,然后是 3 个字符。为什么会这样?