Write a program email c that asks the user for a first and l
Solution
Please find the required program along with its output. Please see the comments against each line to understand the step.
#include <stdio.h>
 #include <string.h>
int main(void) {
 
     int i=0, j=0;
    char name[10];
printf(\"Enter name: \");
 scanf(\"%[^\ ]%*c\",&name); //read name string that allows every character except enter
while (name[i] != \' \') { //find the position of first space
 i++;
 }
int spacePos = i;
   
 char email[15];
 char suffix[10] = \"@ucsd.edu\"; //email suffix
email[0] = tolower(name[0]); //get the first char
   
 for(i=1, j=1; name[i] != \'\\0\' && j<=7; i++){ //loop till we reach first 7 char or end of name
   
 char c = tolower(name[spacePos+i]); //get char at position i
   
 if(c >= \'a\' && c <= \'z\') { //if char c is an alphabet between a-z, then append it to email string
    email[j++] = c;
 }
 }
   
 strcat(email,suffix); //at the end, add suffix to the email strings end
   
 printf(\"UCSD email ID: %s\ \",email); //print final email
   
 return 0;
 }
------------------------------------------------
OUTPUT:
sh-4.3$ main
Enter name: Hillary Clinton
UCSD email ID: hclinton@ucsd.edu
sh-4.3$ main
Enter name: Elizabath Bowes-Lyon
UCSD email ID: ebowesly@ucsd.edu
sh-4.3$ main
Enter name: Andew lloyd webber
UCSD email ID: alloydwe@ucsd.edu


