Input a password from the user and check if it has a char, alphabet and digit

前端 未结 4 389
梦谈多话
梦谈多话 2021-01-23 19:48

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

4条回答
  •  猫巷女王i
    2021-01-23 20:03

    • Point 1. Always initialize your automatic local variables. Saves you from accidentally accessing un-initialized value.

      char arr[10] = {0};
      
    • Point 2. Always limit your input length. Saves you from running into undefined behavior by overrunning the allocated memory by longer-than-expected input.

      scanf("%9s",arr );
      
    • Point 3. Use strlen() to loop over only the valid part of input.

提交回复
热议问题