#include #include #include #define MAX 100 int main(){ char hoten[MAX]; char email[MAX] = ""; char mssv[7]; printf("Nhap ho ten sinh vien: "); gets(hoten); printf("Nhap ma so sinh vien: "); gets(mssv); printf("Ho ten sinh vien la: %s\n", hoten); int l = strlen(hoten); int k = strlen(mssv); int i, m; int j = 0; //Bien dem vi tri cua chuoi email //Gan i tai diem co khoang trang bang cach dem nguoc chuoi HoTen for(i = l - 1; i > 0; i--) if(hoten[i] == ' ') break; //Them chuoi tu vi tri i + 1(i la vi tri tai khoang trang) cua chuoi HoTen tro di vao chuoi email. for(m = i + 1; m < l; m++) email[j++] = hoten[m]; //Them dau cham va chu cai dau tien vao chuoi email email[j++] = '.'; email[j++] = hoten[0]; //Them chu cai dau tien cua chuoi HoTen sau khoang trang vao email for(m = 0; m < i; m++){ if(hoten[m] == ' '){ m++; email[j++] = hoten[m]; } } //Them 4 chu so cuoi mssv vao email for(int s = 3; s < k; s++) email[j++] = mssv[s]; //Chuyen tat ca chu cai thanh chu thuong trong chuoi email for(int t = 0; t <= strlen(email); t++) email[t] = tolower(email[t]); email[j] = 0; printf("Email: %s@sinhvien.hoasen.edu.vn", email); return 0; }