Write a function whose prototype is the int continuemax (CHAR*OUTPUTSTR,CHAR*INPUTSTR) function: Find the longest consecutive number string in the string and return the length of this string, and send this longest number string to one of the function parameters outputstr the memory. For example: After the first address of "ABCD12345E123456789D125SS" is passed to Intputstr, the function returns a value of 123456789 that is referred to by 9,OUTPUTSTR.
#include <iostream> using namespace std;
int Continuemax (char* outputstr,char* inputstr) {int max=0;//string with longest consecutive length int cnt;//record number of consecutive numeric characters char* tmp0=null;
char* Tmp1=null;
int i;
for (;;)
{while (*inputstr! = 0 && (*inputstr > ' 9 ' | | *inputstr < ' 0 '))//skip non-numeric characters ++inputstr; CNT = 0;
Must clear 0 tmp0=inputstr;
while (*inputstr! = 0 && (*inputstr >= ' 0 ' && *inputstr <= ' 9 '))//detect numeric characters {++cnt;
++INPUTSTR;
} if (cnt > Max) {max=cnt; Tmp1=tmp0;
Tmp1 points to the longest first address of consecutive numeric characters} if (*inputstr = = 0)//The string ends after jumping out of the loop break;
} for (I=0;i<max;++i)//To copy the longest consecutive number string into Outputstr * (outputstr+i) =* (tmp1+i); * (outputstr+i) = ' + ';
String ending character return max;
} int main () {char* inputstr= "abcd12345ed125ss123456789";
Char outputstr[100];
int Max;
Max=continuemax (OUTPUTSTR,INPUTSTR);
cout<<max<< "" <<outputstr<<endl;
System ("pause");
return 0; }