char1

Màu nền
Font chữ
Font size
Chiều cao dòng

#include<iostream.h>

#include<conio.h>

#include<string.h>

#include<ctype.h>

// hàm chuẩn hóa tên.

void xoakhoangtrang(char *s)

{

char *c=strstr(s,"  ");

while(c!=NULL)

{

int t=strlen(s)-strlen(c);

for(int i=t;i<strlen(s);i++)

s[i]=s[i+1];

c=strstr(s,"  ");

}

if(s[0]==' ')

s=s+1;

int n=strlen(s);

if(s[n-1]==' ')

s[n-1]='\0';

cout<<s;

}

//hàm chuyển chuỗi thành chữ thường

void chuthuong(char *s)

{

for(int i=0;i<strlen(s);i++)

if(s[i]>=65 && s[i]<=90)

s[i]=s[i]+32;

cout<<s;

}

//hàm chuyển chuỗi thành chữ hoa

void chuhoa(char *s)

{

for(int i=0;i<strlen(s);i++)

s[i]=toupper(s[i]);

cout<<s;

}

//hàm xem kẽ chuỗi chữ thường chữ hoa

void chuxenke(char *s)

{

int n=strlen(s);

for(int i=0;i<n;i++)

{

if(i%2==0)

if((int)s[i]>=97 && (int)s[i]<=122)

s[i]=char((int)s[i]-32);

if(i%2==1)

if((int)s[i]>=65 && (int)s[i]<=90)

s[i]=char((int)s[i]+32);

}

cout<<s;

}

//hàm đảo chuỗi

void daochuoi(char *s)

{

for(int i=strlen(s);i>=0;i--)

cout<<s[i];

}

//hàm cắt họ+tên lót, tên

void cathoten(char *s)

{

char *t;

int i;

for(i=strlen(s);i>=0;i--)

if(s[i]==' '&&s[i+1]!=' ')

break;

t=s+i+1;

s[i]='\0';

cout<<endl<<"ho va ten lot:";

cout<<s<<endl;

cout<<endl<<"ten:";

cout<<t<<endl;

}

//hàm tách tên lót

void tachtenlot(char *s)

{

int j=0;

for(int i=strlen(s)-1;s[i]!=' ';i--)

j++;

for(i=strlen(s)-j;i<strlen(s);i++)

cout<<s[i];

}

//hàm tách họ

void tachho(char *s)

{

for(int i=0;s[i]!=' ';i++)

{cout<<s[i];}

}

//hàm tách tên

void tachten(char *s)

{

char *t;

int i;

for(i=strlen(s);i>=0;i--)

if(s[i]==' '&&s[i+1]!=' ')

break;

t=s+i+1;

s[i]='\0';

cout<<endl<<"tach ten:";

cout<<t<<endl;

}

void main()

{

clrscr();

char s[100];

cout<<"nhap chuoi:";cin.get(s,100);

cout<<endl<<"Chuan hoa chuoi:";

xoakhoangtrang(s);

cout<<endl<<"Chuoi chu thuong:";

chuthuong(s);

cout<<endl<<"Chuoi chu hoa:";

chuhoa(s);

cout<<endl<<"Chuoi Dao Nguoc:";

daochuoi(s);

cout<<endl<<"Xen ke chuoi:";

chuxenke(s);

cathoten(s);

cout<<"ten lot:";

tachtenlot(s);

cout<<endl<<"tach ho:";

tachho(s);

cout<<endl;

tachten(s);

getch();

}

Bạn đang đọc truyện trên: Truyen2U.Pro