Topic:
There is a string that conforms to the following characteristics ("Abcdef,acccd,eeee,aaaa,e3eeeee,sssss,"),
Required to write a function (interface), output the following results
1) The string is separated by commas, the two-dimensional array is formed, and the result is transmitted.
2) The results of the two-dimensional array rows are also spread out.
Please define an interface (function) yourself.
Requirement 1: Can correctly express the requirements of the function, define the interface (function) (30 points);
Requirement 2: Properly implement the interface (function), and realize the function (40 points);
Requirement 3: Write the correct test case. (30 points).
Header file # include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h>/* C language does not have the BOOL type variable, therefore uses the int type to replace */int divstring (const char *buf, char C, char **des, int *count) {int i=0;//loop variable int ncount=0;//Two-dimensional array row Count Char *p, *q;//pointer variable assert (NULL!=BUF), assert (Null!=des), assert (Null!=count);p =q=buf;//Pointer all point to the beginning of the string p=strchr (Buf,c); /Look for character CIF (P==null) {return 0;//not found C, return 0}while (p!=null) {memcpy (des[ncount],q,p-q);d es[ncount][p-q]= ' + ';p ++;q=p;p =STRCHR (p,c); ncount++;} *count=ncount;return 1;//program runs correctly, returns 1}//main function, test case int main () {char buf[50]= "abcdef,acccd,eeee,aaaa,e3eeeee,sssss,"; int Count;int I=0;char c= ', ';//For a level two pointer request memory space char **des= (char * *) malloc (10*sizeof (char *)); if (des==null) {return;} for (i=0; i<10; i++) {des[i]= (char *) malloc (100);} if (divstring (Buf,c,des,&count)) {for (i=0; i<count; i++) {printf ("%s\n", Des[i]);}} Frees memory space for (i=0; i<10; i++) {free (des[i]);} if (DES) {free (DES);}}
String faces a comma-separated string of questions to form a two-dimensional array