Using C(89). A fashion retailer has decided to provide discount codes to teachers and students during a promotional event. The first step is to verify the teacher/student status of people requesting discount code by their email addresses. They will check if the email addresses end with ".edu" and find the domain name if it does before further verification. Write a program to find the domain name of an email address if the domain name ends with .edu. The program displays domain that ends with edu. If the input does not contain an email address that ends with .edu, the program should display a message that indicates it is not a valid email address for the discount code.
Example input/output:
Input: jennifer23@nyu.edu
Output: nyu.edu
Input: joeW19@mail.usf.edu
Output: mail.usf.edu
Input: johnA@facebook.com/
Output: Not a valid email address for the discount code
Your program should include the following function: int find_domain(char *s1, char *s2);
NOTE:
1) The find_domain function expects s1 to point to a string containing the input for an email address as a string and stores the domain to the string pointed by s2. If the email address does not end with .edu, s2 should contain an empty string. An empty string is a valid string with no characters except the null character. The function returns 1 if the email addresses ends with .edu in the domain, and returns 0 otherwise.
2) The find_domain function should use pointer arithmetic (instead of array subscripting). In other words, eliminate the loop index variables and all use of the [] operator in the function.
3) To read a line of text, use the read_line function (the pointer version):
}
int read_line(char *str, int n)
{
int ch; int i = 0;
while ((ch = getchar()) != '\n')
{ if (i < n)
{ *str++= ch;
i++;
}
}
* str = '\0'; /* terminates string */
return i; /* number of characters stored */
}
#include <stdio.h>
#include <string.h>
int read_line(char *str, int n) {
int ch; int i = 0;
while ((ch = getchar()) != '\n'){
if (i < n) {
*str++= ch;
i++;
}
}
*str = '\0'; /* terminates string */
return i; /* number of characters stored */
}
int find_domain(char *email, char *dest) {
// first find @ int i =0;
int len = strlen(email);
while(*email) {
if(*email == '@') {
break;
}
email++;
len--;
}
if(*email != '@' || len < 3) {
*dest = '\0';
return 0;
}
email++; // to remove @
len--;
char *domainStart = email;
// check last 3 characters
while(len != 3) {
email++;
len--;
}
if(strcmp(email, "edu") == 0) {
strcpy(dest, domainStart);
return 1;
}
*dest = '\0';
return 0;
}
int main(void) {
char str[100];
char domain[100];
printf("Enter email: ");
int len = read_line(str, 100);
if(find_domain(str, domain)) {
printf("%s\n", domain);
} else {
printf("Invalid email\n");
}
return 0;
}

Please upvote, as i have given the exact answer as asked in
question. Still in case of any concerns in code, let me know in
comments. Thanks!
Using C(89). A fashion retailer has decided to provide discount codes to teachers and students during...
Write a C program that takes two sets of characters entered by the user and merge them character by character. Enter the first set of characters: dfn h ate Enter the second set of characters: eedtecsl Output: defend the castle Your program should include the following function: void merge(char *s3, char *s1, char *s2); The function expects s3 to point to a string containing a string that combines s1 and s2 letter by letter. The first set might be longer...
Write a program that replace repeated three characters in a string by the character followed by 3. For example, the string aabccccaaabbbbcc would become aabc3ca3b3cc. When there are more than three repeated characters, the first three characters will be replaced by the character followed by 3. You can assume the string has only lowercase letters (a-z). Your program should include the following function: void replace(char *str, char *replaced); Your program should include the following function: void replace(char *str, char *replaced);...
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...
using c language String Challenge Have the function StringChallenge(str) read str which will contain two strings separated by a space. The first string will consist of the following sets of characters: +, *, $, and {N} which is optional. The plus (+) character represents a single alphabetic character, the ($) character represents a number between 1-9, and the asterisk (*) represents a sequence of the same character of length 3 unless it is followed by {N} which represents how many...
****C PROGRAMMING**** (100 points) Write a program that prompts the user to enter the name of a file. The program encoded sentences in the file and writes the encoded sentences to the output file. Enter the file name: messages.txt Output: encoded words are written to file: messages.txt.swt The program reads the content of the file and encodes a sentence by switching every alphabetical letter (lower case or upper case) with alphabetical position i, with the letter with alphabetical position 25...
Write a program **(IN C)** that displays all the phone numbers in a file that match the area code that the user is searching for. The program prompts the user to enter the phone number and the name of a file. The program writes the matching phone numbers to the output file. For example, Enter the file name: phone_numbers.txt Enter the area code: 813 Output: encoded words are written to file: 813_phone_numbers.txt The program reads the content of the file...
Assignment 14.3: Valid Email (10 pts)
image source
Write a program that takes as
input an email address, and reports to the user whether or not the
email address is valid.
For the purposes of this
assignment, we will consider a valid email address to be one that
contains an @ symbol
The program must allow the user
to input as many email addresses as desired until the user enters
"q" to quit.
For each email entered, the
program should...
Write a C++ program that repeatedly reads lines until an EOF is encountered. As each line is read, the program strips out all characters that are not upper or lower case letters or spaces, and then outputs the line. Thus, the program acts as a filter and issues no prompt. There are many ways this program could be written, but to receive full credit, you must observe the following: Place your code in a file called filterChars.cpp. The program should...
Consider the following C++ program. It reads a sequence of strings from the user and uses "rot13" encryption to generate output strings. Rot13 is an example of the "Caesar cipher" developed 2000 years ago by the Romans. Each letter is rotated 13 places forward to encrypt or decrypt a message. For more information see the rot13 wiki page. #include <iostream> #include <string> using namespace std; char rot13(char ch) { if ((ch >= 'a') && (ch <= 'z')) return char((13 +...
1. You are given a C file which contains a partially completed
program. Follow the instructions contained in comments and complete
the required functions. You will be rewriting four functions from
HW03 (initializeStrings, printStrings, encryptStrings,
decryptStrings) using only pointer operations instead of using
array operations. In addition to this, you will be writing two new
functions (printReversedString, isValidPassword). You should not be
using any array operations in any of functions for this assignment.
You may use only the strlen() function...