Enter 3 strings, which are exported in short to long strings, requiring pointers.
#include "stdafx.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace Std;
Char a[80],b[80],c[80];
Char *p1,*p2,*p3;
Enter three strings, three character-type pointers three strings respectively
int _tmain (int argc, _tchar* argv[])
{
void Bijiao (); Because Bijiao is defined after the main function, it is first declared
cin>>a;
cin>>b;
cin>>c;
P1=a;
P2=b;
P3=c;
Bijiao ();
return 0;
}
function change exchange of strings stored in a two-character array
void Change (char *a,char *b)
{
Char t[100];
strcpy_s (T,80,a); strcpy_s is a secure version of the library function strcpy, where it copies a string starting from address A and containing a null terminator to the address space of the array T
strcpy_s (A,80,B);
strcpy_s (b,80,t);
}
function Bijiao Compare three string lengths and sort by short to long
void Bijiao ()
{
int a_l,b_l,c_l;
A_l=strlen (a); The Strlen function calculates the length of the string, plus the <string> header file when used
B_l=strlen (b);
C_l=strlen (c);
if (a_l>b_l)
{
Change (P1,P2);
}
if (a_l>c_l)
{
Change (P1,P3);
}
if (b_l>c_l)
{
Change (P2,P3);
}
cout<<endl;
cout<<a<<endl;
cout<<b<<endl;
cout<<c<<endl;
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Enter 3 strings, output in short to long order by string