Enter 3 strings, output in short to long order by string

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.