-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsplitstr.c
37 lines (30 loc) · 1018 Bytes
/
splitstr.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
35
36
37
/* Split a char string into text fields */
#include "stride.h"
int SplitString(char *Buffer, char **Fields, int MaxField)
{
int FieldCnt, SymbCnt, FieldFlag, BuffLen;
static char LocalBuffer[BUFSZ];
FieldCnt =0; FieldFlag = 0;
BuffLen = (int)strlen(Buffer) - 1;
strcpy(LocalBuffer,Buffer);
for(SymbCnt=0; SymbCnt<BuffLen; SymbCnt++) {
if( (isspace(LocalBuffer[SymbCnt])) && FieldFlag == 0 && SymbCnt != BuffLen-1 ) continue;
if( (!isspace(LocalBuffer[SymbCnt])) && FieldFlag == 1 && SymbCnt == BuffLen-1 ) {
LocalBuffer[SymbCnt+1] = '\0';
return(FieldCnt);
}
else
if( (isspace(LocalBuffer[SymbCnt])) && FieldFlag == 1 ) {
LocalBuffer[SymbCnt] = '\0';
FieldFlag = 0;
if( FieldCnt == MaxField ) return(FieldCnt);
}
else
if( (!isspace(LocalBuffer[SymbCnt])) && FieldFlag == 0 ) {
FieldFlag = 1;
Fields[FieldCnt] = LocalBuffer+SymbCnt;
FieldCnt++;
}
}
return(FieldCnt);
}