- 论坛徽章:
- 0
|
Thanks lin5161678.
多谢各位的建议,还是自己写了,代码如下:
102 // Separate string based on given char
103 int separateString(char *string, char c, char **container)
104 {
105 int z = 0;
106 int x, y = 0;
107 int tokenNum = 0;
108 int length = strlen(string);
109
110 char buff1[MAX_LINE_LEN];
111 char array[MAX_LINE_LEN];
112
113 for (x = 0; x < length; x++){
114 if (string[x + 1] == '\0'){
115 buff1[z] = string[x];
116 buff1[z + 1] = '\0';
117 if (strlen(buff1)){
118
119 strcpy(container[y], buff1);
120
121 tokenNum++;
122 }
123 }
124 else if (string[x] != c){
125 buff1[z] = string[x];
126 z++;
127 if (string[x + 1] == c){
128 buff1[z] = '\0';
129 z = 0;
130 if (strlen(buff1)){
131
132 strcpy(container[y], buff1);
133 y++;
134
135 tokenNum++;
136 }
137 }
138 }
139 }
140 return(tokenNum);
141 }
部分别人的代码,自己改的。 各位还有别的好的实现吗? |
|