A comma-delimited string of "string" questions to form a two-dimensional array

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.