本文目录一览:
C语言split分割字符串。
//以下解法的前提是,先把所有环变成1.无环路,2.一个环没有扣住3个及以上的其他环
void main(){
int array[16] = {0};
//init, array[1] = xxx;根据输入初始化数组,如1-2,则,array[1] = 2,...
int HashArray[16] = {0};
int head, tail;
int head_tmp, tail_tmp;
getNextList(array, HashArray, head, tail);
while(getNextList(array, HashArray, head_tmp, tail_tmp))
{
array[tail] = head_tmp;
tail = tail_tmp;
}
//此时的array数组里面应该是一条链了
}
getNextList(int array[], int Hasharray, int head, int tail)
{
int head_tmp = 1;
while(Hasharray[head_tmp++] != 0);
if (head_tmp == 16)
return false;
else
{
head = tail = head_tmp - 1;
while(array[tail] != 0)
{
Hasharray[tail] = 1;
tail++;
}
Hasharray[tail] = 1;
return true;
}
}
C语言中字符切割函数split的实现
#include stdio.h
#include string.h
// 将str字符以spl分割,存于dst中,并返回子字符串数量
int split(char dst[][80], char* str, const char* spl)
{
int n = 0;
char *result = NULL;
result = strtok(str, spl);
while( result != NULL )
{
strcpy(dst[n++], result);
result = strtok(NULL, spl);
}
return n;
}
int main()
{
char str[] = "what is you name?";
char dst[10][80];
int cnt = split(dst, str, " ");
for (int i = 0; i cnt; i++)
puts(dst[i]);
return 0;
}
C语言中字符切割函数split的实现是什么?
c语言中 有切割字符串的函数啊!\x0d\x0a\x0d\x0astrtok函数(const char *str, const char *ch)\x0d\x0a\x0d\x0a第一个是字符串,第二个是以那个字符做切割。\x0d\x0a\x0d\x0a例子:\x0d\x0a#include \x0d\x0a#include \x0d\x0aint main(void)\x0d\x0a{\x0d\x0achar s[] = "123-sldkf-123ls-343434-dfjdlkfj-dflcmvn";\x0d\x0achar *delim = "-";\x0d\x0achar *p;\x0d\x0aprintf("%s ", strtok(s, delim));\x0d\x0awhile((p = strtok(NULL, delim))\x0d\x0aprintf("%s ", p);\x0d\x0aprintf("\n");\x0d\x0areturn 0;\x0d\x0a} \x0d\x0a\x0d\x0achar s[] = "dlkjf-sdlkfjsdf\lsdkljfl'sldkjf\sdkfjsdlf\lskdjfls";\x0d\x0a如果想用-和\两个符号切割的话\x0d\x0achar *delim = "-\";\x0d\x0a这样就可以了