// 1. write a function. The original form is int continumax (char * outputstr, char * intputstr) // function: // find the longest consecutive numeric string in the string, return the length of the string, // and pay the longest numeric string to the memory specified by one of the function parameters outputstr. // For example, after the first address of "abcd12345ed125ss123456789" is passed to intputstr, the function returns 9, and the value indicated by 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]! = '\ 0') {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] = '\ 0 '; 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 ;}
# Include <iostream. h> # include <malloc. h> int continumax (char * outputstr, char * inputstr) {int len = 0; // count the length of the numeric string int max = 0; // The length of the current maximum numeric string char * pstr = NULL; // records the starting position of the maximum numeric character while (* inputstr! = '\ 0') {if (* inputstr <= '9' & * inputstr> = '0') // counts the length of the number substring {len ++; inputstr ++; continue;} else if (len> max) // if the calculated numeric string is greater than the length of the current maximum numeric substring, update {max = len; pstr = inputstr-len; len = 0;} inputstr ++;} for (int I = 0; I <max; I ++) // copy the maximum substring value to outputstr {* outputstr = * pstr; outputstr ++; pstr ++;} outputstr = outputstr-max; outputstr [max] = '\ 0'; 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 ;}