Wang Liping -- split string, Wang Liping -- split string

Source: Internet
Author: User

Wang Liping -- split string, Wang Liping -- split string

Compile a split string splitting function in C.

This is written in c ++, but it is similar to the principle of c. I have run it. ask another question. c doesn't know whether it can run, but now the c/c ++ programming test system usually has nested c ++. You can click vc6.0 to create a project to run it when you open the c interface.
# Include <iostream>
Using namespace std;

Char ** split (char p [], char c, int k)
{
Int I, m, j;
Char ** q;
Q = (char **) new char * [k];
For (I = 0; I <k; I ++)
Q [I] = (char *) new char * [20];
I = 0;
J = 0;
M = 0;
While (p [I])
{
If (p [I]! = ',')
{
Q [j] [m ++] = p [I ++];

}
Else
{
Q [j] [m] = '\ 0 ';
J ++;
M = 0;
I ++;

}

}
Q [k-1] [m] = '\ 0 ';

For (I = 0; I <4; I ++)
{

Cout <q [I];
Cout <endl;

}
Return q;

}
Void main ()
{Int k;
Char p [] = "AB, cde, efgh, ghi32 ";
Char c = ',';
Int I = 0, j = 0, m = 0;

While (p [I])
{
If (p [I] = ',')
J ++;
I ++;

}
J = j + 1; // determine the number of words that have been accepted by commas after segmentation
K = j;
Char ** q = split (p, c, k );
Printf ("\ n ");
For (I = 0; I <4; I ++)
{
Cout <q [I];
Cout <endl;

}

}

Program Statement Translation

What is the order?

Related Article

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.