Variable
I have a code like the following :
char password[32];
printf("Input Password :");
scanf("%s",password);
printf("You put :%s",password);
If i put something like "secret",it will be ok,"secret" will be printed out.But if i put something like "very secret" only secret is displayed not "very secret".Can you tell me what is the reason?
[376 byte] By [
kurumi] at [2007-11-19 22:47:21]

# 2 Re: Variable
I have a code like the following :
char password[32];
printf("Input Password :");
scanf("%s",password);
printf("You put :%s",password);
If i put something like "secret",it will be ok,"secret" will be printed out.But if i put something like "very secret" only secret is displayed not "very secret".Can you tell me what is the reason?
You can't use scanf to get more than one word. If you want to get more than one word then use "gets"
for example:
char password[32];
printf("Input Password :");
gets(password);
printf("You put :%s",password);
# 4 Re: Variable
If i put something like "secret",it will be ok,"secret" will be printed out.But if i put something like "very secret" only secret is displayed not "very secret".
If you enter "very secret" scanf should take the "very" part not "secret".
Anyway, budihartanto is generally right but since we are talking about passwords and security here :) I would recommend
gets_s(password, sizeof password / sizeof password[0]);