My doubt is that, the program works fine if I enter a password that fills the array. However if I enter a password such as \"apple25\", I think it counts the blank spaces in the
That's because your loop runs over the entire, not just upto the characters you read.
Instead do,
size_t len = strlen(arr);
for (i=0; i
You may also want to use fgets() to avoid buffer overrun. If you enter more than 10 characters, you'll overflow arr
, which is undefined behaviour.
Instead of
scanf("%s",arr );
do
fgets(arr, sizeof arr, stdin);
char *p = strchr(arr, '\n');
if(p) *p = 0; //trim the trailing newline, if present