Copy Code code as follows:
1. Write a function, its prototype is int Continumax (char *outputstr,char *intputstr)
Function:
In the string, find the longest string of digits and return the length of this string,
and the longest number string is paid to one of the function parameters outputstr the memory referred to.
For example: After the first address of "abcd12345ed125ss123456789" is passed to Intputstr, the function returns the value of 9,outputstr is 123456789
#include <stdio.h>
#include <assert.h>
int Continumax (char *outputstr,char *inputstr)
{
ASSERT (OUTPUTSTR);
ASSERT (INPUTSTR);
int length = 0;
int maxlength = 0;
int i = 0;
int j = 0;
while (Inputstr[i]!= ' ")
{
while (Inputstr[i] >= ' 0 ' && inputstr[i] <= ' 9 ')
{
length++;
i++;
}
if (length > MaxLength)
{
maxlength = length;
int k = I-maxlength;
for (j = 0; J < MaxLength; J + +)
{
OUTPUTSTR[J] =inputstr[k++];
}
length = 0;
Continue
}
i++;
length = 0;
}
OUTPUTSTR[J] = ' the ';
return maxlength;
}
int main ()
{
Char inputstr[]= "abcd12345eddafsd125ss123456789";
Char outputstr[100];
int max_numstr_length = Continumax (OUTPUTSTR,INPUTSTR);
printf ("%s\n", outputstr);
printf ("The Max_numstr_length is%d\n", max_numstr_length);
return 0;
}
Copy Code code as follows:
#include <iostream.h>
#include <malloc.h>
int Continumax (char * outputstr, char * inputstr)
{
int len = 0; To count the length of a numeric string
int max = 0; The length of the current maximum number string
Char *pstr =null; Record the starting position of the largest numeric character
while (* inputstr!= ' ")
{
if (*inputstr <= ' 9 ' && *inputstr >= ' 0 ')///The length of the number substring
{
len++;
inputstr++;
Continue
}
else if (len > Max)//If the calculated number string is greater than the length of the current maximum number substring, update
{
max = Len;
Pstr = Inputstr-len;
len = 0;
}
inputstr++;
}
for (int i = 0; i<max;i++)//Copy the value of the largest substring to OUTPUTSTR
{
*outputstr = *pstr;
outputstr++;
pstr++;
}
Outputstr = Outputstr-max;
Outputstr[max] = ' the ';
cout<<outputstr<<endl;
return Max;
}
int main ()
{
Char input[] = "de1234de123456ed";
char * out = (char *) malloc (100*sizeof (char));
Char output[100];
int max = Continumax (output, input);
cout<<max<<endl;
return 0;
}