• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

wchenfeng

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

输入几个字符串,比较找出其中最小的字符串

#include<stdio.h>
#include<string.h>
#define N 20
#define M 81
int getstr(char p[][M])
{
    char t[M],n=0;
    printf("enter string a empty string to end\n");
    gets(t);
    while(strcmp(t,""))
    {
        strcpy(p[n],t);
        n++;
        gets(t);
    }
    return n;
}
char *findmin(char(*a)[M],int n)
{
    char *q; int i;
    q=a[0];
    for(i=1;i<n;i++)
        if(strcmp(a[i],q)<0)
            q=a[i];
    return q;
}
int main()
{
    char s[N][M],*sp;int n;
    n=getstr(s);
    sp=findmin(s,n);
    puts(sp);
}

 

posted on 2022-04-12 20:04  王陈锋  阅读(125)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3