当前位置:网站首页>【指针】查找最大的字符串
【指针】查找最大的字符串
2022-07-06 09:24:00 【|光|】
要求
编一个函数,找出其中最大的字符串。(用指针实现)
代码
#include<string.h>
#include<stdlib.h>
/* * 该函数用来实现查找n个字符串中最大的那一个 * a是二维字符数组,每一行存放一个字符串,n为带查找的字符串的个数 */
char * find_max_string(char a[][300],int n)
{
char *pmax;
int i, j = 0, k;
for (i = 0; i < n; i++)
{
k = strcmp(a[j],a[i]);
if (k < 0)
{
j = i;
}
}
pmax = &a[j-1][300];
return pmax;
}
main函数
int main()
{
char a[10][300]={
0},*p;
int n=0;
while(gets(a[n])!=NULL){
n++;
}
p=find_max_string(a,n);
puts(p);
return 0;
}
测试
测试输入
I love China
I Love China
I have dream
输出
I love China
边栏推荐
- XSS之冷门事件
- Realize applet payment function with applet cloud development (including source code)
- On the idea of vulnerability discovery
- 中间件漏洞复现—apache
- Hackmyvm target series (2) -warrior
- 7-8 7104 Joseph problem (PTA program design)
- Data mining - a discussion on sample imbalance in classification problems
- Record an edu, SQL injection practice
- . Net6: develop modern 3D industrial software based on WPF (2)
- Proceedingjoinpoint API use
猜你喜欢
记一次edu,SQL注入实战
Statistics 8th Edition Jia Junping Chapter 7 Summary of knowledge points and answers to exercises after class
Hcip -- MPLS experiment
关于交换a和b的值的四种方法
HackMyvm靶機系列(3)-visions
Hackmyvm target series (4) -vulny
Record an API interface SQL injection practice
New version of postman flows [introductory teaching chapter 01 send request]
Intranet information collection of Intranet penetration (2)
SystemVerilog discusses loop loop structure and built-in loop variable I
随机推荐
Network layer - simple ARP disconnection
Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
sqqyw(淡然点图标系统)漏洞复现和74cms漏洞复现
《统计学》第八版贾俊平第十二章多元线性回归知识点总结及课后习题答案
{1,2,3,2,5}查重问题
Record an API interface SQL injection practice
内网渗透之内网信息收集(二)
图书管理系统
Statistics 8th Edition Jia Junping Chapter 3 after class exercises and answer summary
《统计学》第八版贾俊平第十章方差分析知识点总结及课后习题答案
7-7 7003 combination lock (PTA program design)
Wu Enda's latest interview! Data centric reasons
7-15 h0161. Find the greatest common divisor and the least common multiple (PTA program design)
Bing Dwen Dwen official NFT blind box will be sold for about 626 yuan each; JD home programmer was sentenced for deleting the library and running away; Laravel 9 officially released | Sifu weekly
"Gold, silver and four" job hopping needs to be cautious. Can an article solve the interview?
Statistics 8th Edition Jia Junping Chapter IX summary of knowledge points of classified data analysis and answers to exercises after class
Résumé des points de connaissance et des réponses aux exercices après la classe du chapitre 7 de Jia junping dans la huitième édition des statistiques
Intranet information collection of Intranet penetration (5)
Mysql的事务是什么?什么是脏读,什么是幻读?不可重复读?
JDBC事务、批处理以及连接池(超详细)