Question: C - language Write a program that takes a word entered by the user, check if the word is a valid username. If the input
C - language
Write a program that takes a word entered by the user, check if the word is a valid username. If the input is valid, print a confirmation statement. If it is not, print a statement that the input is not valid.
1) The user name has at least 5 characters, and at most 10 characters
2) It must contain alphabetic letters (upper or lower case), digit or underscore, but no space or other punctuations
For example, zone8 is valid and zone!8 is invalid
The user input ends with the user pressing the enter key (a new line character).
3) Use getchar() to read in the input.
4) You can use character handling functions such as isdigit and isalpha. Dont forget to include ctype.h if you use any character handling functions.
Can you guys don't use array - list for this problem?
This is mine so far:
#include
#include
int main()
{
int name;
int len = 0;
printf("enter id: ");
name = getchar();
while (name != ' ')
{
len ++;
name = getchar();
}
printf("len %d ", len);
if (len < 5 || len > 10 || isspace(name) || ispunct(name))
{
printf("invalid");
}
else
{
printf("valids");
}
return 0;
}
The issues of my program are in if - else statement! it did not work, it worked in about checking the len but the if-esle did not work. Please show me in more detail, I appreciate that!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
