Question

Please help me write down a program to check email address valid or not. Tip:parse the...

Please help me write down a program to check email address valid or not.
Tip:parse the string and count the special characters like '@', '.' .and at least one character.
Suggested libc functions: printf()
1.Have to be by the argc/argv of main function
2.Connot use scanf/getchar and other user input functions
3.Please explain the details and steps for me cause I'm a beginner hhhhhh
Thank you soooo much for helping me!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note:

The program has been written in C as you didn't specify the language.

Code:

#include<stdio.h>

int main(int argc, char**argv)

{

    // If email is not passed as the command argument

    if(argc==1)

    {

        // Printing the message onto the console that email is not entered

        printf("Email not entered\n");

    }

    // If more than one command argument is passed to the program (excluding the object file name)

    else if(argc>2)

    {

        // Printing the message onto the console that too many arguments have been passed

        printf("Too many arguments passed to the program\n");

    }

    // Else, parse the email

    else

    {

        // This variable is used to keep track of current index of the email string

        int email_char_index = 0;

        // This variable is used to keep track of how many special characters have been found

        int special_characters = 0;

        // This variable is used to keep track of how many characters have been found

        int characters = 0;

        // Iterating over the string until end is reached

        while(argv[1][email_char_index]!= '\0')

        {

            

            // If the value at argv[1][email_char_index] is an lowercase alphabet, then it is a character

            if(argv[1][email_char_index] >= 'a' && argv[1][email_char_index] <= 'z'){++characters;}

            // If the value at argv[1][email_char_index] is an uppercase alphabet, then it is a character

            else if(argv[1][email_char_index] >= 'A' && argv[1][email_char_index] <= 'Z'){++characters;}

            // If the value at argv[1][email_char_index] is an digit, then it is a character

            else if(argv[1][email_char_index] >= '0' && argv[1][email_char_index] <= '9'){++characters;}

            // If the value at argv[1][email_char_index] is none of the above, then it is a special character

            else{++special_characters;}

            // Pre incrementing the email_char_index

            ++email_char_index;

        }

        // According to the given tip, the email should have more than one character and zero or more special charcters.

        // So if those two conditions are passed, then the email is valid

        if(special_characters >= 0 && characters > 0)

        {

            printf("Entered email is %s and it is a valid email\n",argv[1]);

        }

        // Else, the email is invalid

        else

        {

            printf("Entered email is %s and it is not a valid email\n",argv[1]);

        }        

    }

    return 0;

}

Sample Output:

Add a comment
Know the answer?
Add Answer to:
Please help me write down a program to check email address valid or not. Tip:parse the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please help me to write a program to check telephone number validity . (just check all...

    Please help me to write a program to check telephone number validity . (just check all characters are "0"~"9") 1.C language 2.Please use "printf"(no scanf、gets....) 3.only argv ,argc accepted 4.Please explain the steps (cause I'm a beginner hhhhh) Thank you soooooo much!!!!!

  • Please write MIPS program that runs in QtSpim (ex: MipsFile.s) Write a MIPS program that will...

    Please write MIPS program that runs in QtSpim (ex: MipsFile.s) Write a MIPS program that will read in a base (as an integer) and a value (nonnegative integer but as an ASCII string) in that base and print out the decimal value; you must implement a function (which accepts a base and an address for a string as parameters, and returns the value) and call the function from the main program. The base will be given in decimal and will...

  • Help please this is C/C++ code /* * Lab12, the purpose of this lab is to...

    Help please this is C/C++ code /* * Lab12, the purpose of this lab is to improve your skills in handling c strings * with pointers . * use of : strlen ,string concatenation strcat, compare strcmp, * copy strcpy and search strrchr * */ #include <cstdlib> #include <iostream> #include<cstring> using namespace std; /** * Create a method that prompts the user for only lowercase letters to represent * a name. * Start a Label, then prompt the user to...

  • Write a complete C program that inputs a paragraph of text and prints out each unique...

    Write a complete C program that inputs a paragraph of text and prints out each unique letter found in the text along with the number of times it occurred. A sample run of the program is given below. You should input your text from a data file specified on the command line. Your output should be formatted and presented exactly like the sample run (i.e. alphabetized with the exact spacings and output labels). The name of your data file along...

  • Create a UNIX makefile for the following C program: //convert.c char toUpper(char c){ if(c>='a' && c<='z')...

    Create a UNIX makefile for the following C program: //convert.c char toUpper(char c){ if(c>='a' && c<='z') return c-32; return c; } //converting sentance to upper void convertSentence(char *sentence){ int i=0; while(sentence[i]!='\0'){ //convert to upper for each character sentence[i] = toUpper(sentence[i]); i++; } } //converting all sentences into uppercase void convertAll(char **sentenceList, int numOfSentences){ int i=0; while(i<numOfSentences){ //calling convertsentence function to conver uppercase convertSentence(sentenceList[i]); i++; } } sentences.c #include<stdio.h> #include<stdlib.h> #include "convert.c" int main(){ //declaring character array char **mySentences; int noOfSentences;...

  • Hi. Could you help me write the below program? Please don't use any header other than...

    Hi. Could you help me write the below program? Please don't use any header other than iostream, no Chegg class, no argc/argv. Nothing too advanced. Thank you! For this assignment you are implement a program that can be used to compute the variance and standard deviation of a set of values. In addition your solution should use the functions specified below that you must also implement. These functions should be used wherever appropriate in your solution. With the exception of...

  • Programming Assignment #2 EE 2372 MAKE SURE TO FOLLOW INSTRUCTIONS CAREFULLY, IF YOU HAVE ANY DOUBTS...

    Programming Assignment #2 EE 2372 MAKE SURE TO FOLLOW INSTRUCTIONS CAREFULLY, IF YOU HAVE ANY DOUBTS PLEASE EMAIL ME! This programming assignment will just be a small extension to programming assignment 1. In the first assignment each of the functions could only take a predefined number of inputs. This time the objective is to be able to complete these functions with any amount of inputs. The user will pass arguments through the command line (this means you will have to...

  • I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I...

    I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I just have to explain a lot so you understand how the program should work. In C programming, write a simple program to take a text file as input and encrypt/decrypt it by reading the text bit by bit, and swap the bits if it is specified by the first line of the text file to do so (will explain below, and please let me...

  • Please help me with those 2 question problem, please help, thanks!! Code (Please use visual studio):...

    Please help me with those 2 question problem, please help, thanks!! Code (Please use visual studio): #include <stdio.h> #include <string.h> #pragma warning(disable : 4996) // compiler directive for Visual Studio only // Read before you start: // You are given a partially complete program. Your job is to complete the functions in order for this program to work successfully. // All instructions are given above the required functions, please read them and follow them carefully. // You shoud not modify...

  • Please help me with this program. Using C++ (printf & scanf) statements. Thank you. ASSIGNMENT: Write...

    Please help me with this program. Using C++ (printf & scanf) statements. Thank you. ASSIGNMENT: Write a program to ask the user for a number that includes a decimal point. Then display the integer part of the number (the part of the number to the left of the decimal point) and the decimal part of the number (the part of the number to the right of the decimal point, including the decimal point Follow the 3 steps in the Information...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT