1. Write a function. Its prototype is intcontinumax (char * outputstr, char * intputstr). function: Find the longest consecutive numeric string in the string and return the length of the string, and pay the longest numeric string to the parameter outputstr.
// 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. The value outputstr indicates is 123456789 # include
# Includeint 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
# Include
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