当前位置:网站首页>C language program practice - (write a function, its prototype is int continumax (char *outputstr, char *intputstr))
C language program practice - (write a function, its prototype is int continumax (char *outputstr, char *intputstr))
2022-07-22 16:41:00 【Light chasing rain】
Write a function , Its original form is int continumax(char *outputstr,char *intputstr).
function :
Find the longest consecutive number string in the string , And return the length of this string ,
And give the longest string of numbers to one of the function parameters outputstr The memory in question .
for example :"abcd12345ed125ss123456789" Send the first address of to intputstr after , Function will return 9,
outputstr The value indicated is 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); This , Just passed in the pointer , use continumax(char *outputstr, char *intputstr) After that , Will degenerate into pointer variables , It can only be modified malloc The value of the inside , It can't be modified outputstr Point to continumax(&outputstr, str); This incoming pointer address , use continumax(char **outputstr, char *intputstr) Connect it with the secondary pointer , Can modify output Point to */
边栏推荐
猜你喜欢
随机推荐
What is SCM? What are the components of SCM?
Beautify multiple digits
Session sharing problem
Operation tutorial: UOB camera registers the detailed configuration of easycvr platform through gb28181 protocol
ECCV 2022 | 修正FPN帶來的大目標性能損害:You Should Look at All Objects
AlterNet Studio 8.1 Crack
把握机器人教育朝AI智能化发展的趋势
信息学奥赛一本通 1977:【08NOIP普及组】立体图 | 洛谷 P1058 [NOIP2008 普及组] 立体图
高数_第2章多元函数微分学_隐函数的偏导数
源启数字化:既有模式,还是开源创新?|砺夏行动
How to write update set a= (select) in PostgreSQL?
左耳朵耗子:云原生时代的开发者应具备这5大能力
Process and thread interview questions
sql server2008数据库查询admin密码
[leetcode string -- string subscript sorting] 6121. Query the number with the smallest k after cutting the number
洛谷_P1112 波浪数_思维_进制 / 构造 / 枚举
Jincang database kmonitor user guide --3. deployment
Network layer interview questions
解析参与机器人教育竞赛的热潮
stm32使用各种传感器的教程