I'm trying to make a tiny account register program. It prompts the user for userID
and password
. I'm working on the userID
part but it doesn't seem right. It works fine if I type in a < 8
characters userID
, but when I type in a userID
with more than 16
characters, the messages asking the user for a different userID
are printed twice. Why's that?
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void)
{
// Setting up variables
char userID[18];
char passcode[51];
// Firstly promt the user for user ID
do // This loop is for asking the user to type another userID if his chosen one isn't approprite
{
printf("Please choose your user ID! (it must be between 6 - 16 charaters long)\n");
for (int i = 0; i < 17; i++) // This loop store the userID into the character array
{
userID[i] = getchar(); // Store userID into array character by character
if (userID[i] == '\n')
{
userID[i+1] = '\0';
break;
}
}
}
while (strlen(userID) < 7 || (strlen(userID) > 16 && userID[16] != '\n'));
// Printing info on the screen.
printf("Your acount info are:\n\tuserID : %s\tpasscode: ", userID);