当前位置:网站首页>C语言程序练习——(写一个函数,它的原形是int continumax(char *outputstr,char *intputstr))
C语言程序练习——(写一个函数,它的原形是int continumax(char *outputstr,char *intputstr))
2022-07-22 04:26:00 【光追雨】
写一个函数,它的原形是int continumax(char *outputstr,char *intputstr)。
功能:
在字符串中找出连续最长的数字串,并把这个串的长度返回,
并把这个最长数字串付给其中一个函数参数outputstr所指内存。
例如:"abcd12345ed125ss123456789"的首地址传给intputstr后,函数将返回9,
outputstr所指的值为123456789
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int continumax(char *outputstr, char *intputstr)
{
int max_num_len = 0;
int flag = 0;
int i = 0;
int count = 0;
int area_i = 0;
int area_end_i = 0;
char *tmp = intputstr;
char s1[1024];
while(tmp[i] != '\0')
{
if(tmp[i] > 47 && tmp[i] < 58)
{
if(flag == 0)
{
area_i = i;
flag = 1;
count++;
}
else if(flag == 1)
{
count++;
}
++i;
}
else
{
if(flag == 1)
{
if(count > max_num_len)
{
area_end_i = i;
max_num_len = count;
int j;
for(j = area_i;j < area_end_i;j++)
{
outputstr[j - area_i] = intputstr[j];
}
}
count = 0;
flag = 0;
}
++i;
}
}
if(flag == 1)
{
if(count > max_num_len)
{
area_end_i = i;
max_num_len = count;
int j;
for(j = area_i;j < area_end_i;j++)
{
outputstr[j - area_i] = intputstr[j];
}
}
count = 0;
flag = 0;
}
return max_num_len;
}
int main ()
{
char *str = "abd1234xsac2231231xasc111";
char *outputstr = (char *)malloc(1024);
int intputstr = continumax(outputstr, str);
printf("intputstr = %d\n", intputstr);
printf("outputstr = %s\n", outputstr);
return 0;
}
/* continumax(outputstr, str); 这个,只是传入了指针 ,用 continumax(char *outputstr, char *intputstr) 接之后,会退化成指针变量,只能修改malloc里面的值,而不能修改 outputstr指向的位置 continumax(&outputstr, str); 这个传入指针地址,用 continumax(char **outputstr, char *intputstr) 用二级指针接之后,能修改output指向的位置 */
边栏推荐
- [ARC116F] Deque Game
- Informatics Olympiad all in one 1977: [08noip popularization group] stereogram | Luogu p1058 [noip2008 popularization group] stereogram
- AcWing_11. 背包问题求方案数_dp
- Process and thread interview questions
- Luogu_ P1112 wave number_ Thinking_ Base / construction / enumeration
- Write a function in C language to delete the spaces in the string and return the number of spaces
- Rquestmapping's annotation function, annotation usage range, and attribute details of annotations
- FTP server setup and deployment and C # realize FTP file upload
- JVM memory model: runtime data area and thread
- Session共享问题
猜你喜欢
NFT exchange contract development tutorial (solidity & hardhat)
Command line code for server and local data transmission
string的模拟实现
分布式调度框架Elastic-Job
Operation tutorial: UOB camera registers the detailed configuration of easycvr platform through gb28181 protocol
screen命令使用
JVM memory model: virtual machine stack
mysql通过开启全局日志进行定位排查慢sql
What is SCM? What are the components of SCM?
Distributed scheduling problem
随机推荐
Leetcode 234. 回文链表
CF464E The Classic Problem
洛谷_P1112 波浪数_思维_进制 / 构造 / 枚举
DNS interview questions of computer network
C# ftp检测目录是否存在和创建文件夹
用c语言编写一个函数用来删除字符串中的空格并返回空格个数
Android interview: 2022 please keep this experience of Netease Android development and Tiktok e-commerce Android engineers
内存管理面试问题
Vulkan official example interpretation subchannel
Switch and router technology: Standard ACL, extended ACL and named ACL
[SSM]SSM整合③(接口测试)
At5662 [agc040d] balance beam (two points)
CF1635F Closest Pair
SFTP creation
The competition of trillion market value public chain is white hot. Is there still a chance for the new public chain?
[solution] solve the importerror: library "Glu" not found
Elephant Swap的LaaS方案迅速崛起,构建全新DeFi2.0协议
MP query criteria
Operation tutorial: UOB camera registers the detailed configuration of easycvr platform through gb28181 protocol
Sort--排序中的 插入排序 和 希尔排序