现在的位置: 首页 > 综合 > 正文

17.2比较两个字符串

2014年02月28日 ⁄ 综合 ⁄ 共 596字 ⁄ 字号 评论关闭
/*
 * Copyright (c) 2013, 烟台大学计算机学院
* All rights reserved.
* 作    者:王颖
* 完成日期:2013 年 12 月 17 日
* 版 本 号:v1.0
*
* 输入描述: 无
* 问题描述:字符串与指针
* 程序输出:略
* 问题分析:比较两个字符串
* 算法设计:略
*/#include <iostream>
#include<string.h>
using namespace std;
int pstrmp(const char *str1,const char *str2);
int main()
{
    int k;
    char a[50]="my name is wangying!",b[50]="you name is maleyi!";
    k=pstrmp(a,b);
    cout<<"The more lenth is:"<<endl;
    if(k==1)
        for(int i=0; i<50; i++)
            cout<<a[i];
    if(k==-1)
        for(int i=0; i<50; i++)
            cout<<b[i];
    if(k==0)
        cout<<"相同!"<<endl;
    return 0;
}
int pstrmp(const char *str1,const char *str2)
{
    int n;
    char s1[50],s2[50];
    str1=s1;
    str2=s2;
    n=strcmp(s1,s2);
    if(n>0)
        return 1;
    if(n<0)
        return -1;
    if(n==0)
        return 0;
}

抱歉!评论已关闭.