当前位置:网站首页>【指针】查找最大的字符串
【指针】查找最大的字符串
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
边栏推荐
- 7-8 7104 Joseph problem (PTA program design)
- Low income from doing we media? 90% of people make mistakes in these three points
- 《统计学》第八版贾俊平第十章方差分析知识点总结及课后习题答案
- 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
- JVM memory model concept
- captcha-killer验证码识别插件
- [err] 1055 - expression 1 of order by clause is not in group by clause MySQL
- Intranet information collection of Intranet penetration (3)
- 《英特尔 oneAPI—打开异构新纪元》
- Statistics 8th Edition Jia Junping Chapter IX summary of knowledge points of classified data analysis and answers to exercises after class
猜你喜欢

Interpretation of iterator related "itertools" module usage

Record an edu, SQL injection practice

《统计学》第八版贾俊平第三章课后习题及答案总结

xray与burp联动 挖掘

Intranet information collection of Intranet penetration (3)

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

《统计学》第八版贾俊平第十四章指数知识点总结及课后习题答案

Tencent map circle

Markdown font color editing teaching

《统计学》第八版贾俊平第八章假设检验知识点总结及课后习题答案
随机推荐
Uibutton status exploration and customization
搭建域环境(win)
Load balancing ribbon of microservices
外网打点(信息收集)
Xray and Burp linked Mining
Hackmyvm target series (4) -vulny
Data mining - a discussion on sample imbalance in classification problems
Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
《统计学》第八版贾俊平第四章总结及课后习题答案
[paper reproduction] cyclegan (based on pytorch framework) {unfinished}
WEB漏洞-文件操作之文件包含漏洞
Fire! One day transferred to go engineer, not fire handstand sing Conquest (in serial)
"Gold, silver and four" job hopping needs to be cautious. Can an article solve the interview?
Mathematical modeling idea of 2022 central China Cup
A complete collection of papers on text recognition
Database monitoring SQL execution
Realize applet payment function with applet cloud development (including source code)
《统计学》第八版贾俊平第五章概率与概率分布
浙大版《C语言程序设计实验与习题指导(第3版)》题目集
HackMyvm靶机系列(3)-visions