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?