Ask Question
26 July, 13:04

Write a program to check if an input is a valid hashtag (starts with #, contains only letters, numbers, and underscore, no space or special characters).

(1) Name your program hashtag. c.

(2) The user input ends with the user pressing the enter key (a new line character).

(3) Library function isalpha (), isdigit (), and isalnum () are not allowed in this program.

(4) Use getchar () to read in the input.

+1
Answers (1)
  1. 26 July, 16:52
    0
    C code is given below

    Explanation:

    #include

    int main ()

    {

    printf ("Input:");

    int ch;

    int valid=1; / / it is set as 1 initially if anything is wrong it is changed to 0

    ch=getchar ();

    if (ch!='#') / / it checks if it starts with #

    {

    valid=0;

    }

    while ((ch = getchar ()) ! = '/n') / / this loop runs till line ends

    {

    if ((ch>='a'&&ch='A'&&ch='0'&&ch<='9') || (ch=='_')) / / if conditions are matched then its okay

    {

    }

    else / / else valid is changed to 0 from 1

    {

    valid=0;

    }

    }

    if (valid==0) / / if anywhere there is anything wrong then it prints not valid

    {

    printf ("It is not valid hashtag");

    }

    else / / else prints valid

    {

    printf ("It is a valid hastag");

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a program to check if an input is a valid hashtag (starts with #, contains only letters, numbers, and underscore, no space or special ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers