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]
# 1 Re: Variable
It's Magic!!!!!!!!!!!!!

try this!!

char password[32];
password [0]='\0';
.........
.......
I am not sure ,I have not tried.
gauravgandhi4all at 2007-11-10 23:32:58 >
# 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);
budihartanto at 2007-11-10 23:34:02 >
# 3 Re: Variable
oh i use gets and solved the problem!Thanks a lot!
kurumi at 2007-11-10 23:35:01 >
# 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]);
Boris K K at 2007-11-10 23:36:01 >