c语言实现遍历字符串并分割成数组

遍历字符串

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
int sepcharbydh(char *in, char caOut[200][256])
{
char *p, *p2;
long lCount;
long m = 0;
lCount = 0;
if (strlen(in) == 0)
return 0;
p = in;
memset(caOut, 0, 200 * 256);
while (*p)
{
if (*p == ',')
{
caOut[lCount][m] = '\0';

m = 0;
p++;
lCount++;
if (lCount >= 200)
return lCount;
}
else
{
if (m < 35)
{
caOut[lCount][m] = *p;
p++;
m++;
}
}
}
return lCount + 1;
}