共有回帖数 0 个
-
有一段时间没用C语言写程序了,今天跟朋友闲聊,于是就顺手写了这么一段代码,权当复习了,有需要的童鞋就看看吧。有些地方还不是很完善,不自豪。
以后准备入住本吧
#include stdio.h
#include windows.h
char** Split(char *pszSource, char cDelimiter, unsigned int *pAmount)
{
unsigned int i = 0, j = 0, amount = 0;
for (; i = strlen(pszSource); i++) {
if (pszSource == cDelimiter) amount++;
}
char **szTemp = (char**)malloc((amount + 1) * 4);
for (i = 0, amount = 0; i = strlen(pszSource); i++) {
if (pszSource == cDelimiter || pszSource == ' ') {
szTemp[amount] = (char*)malloc(i - j + 1);
(szTemp[amount])[i - j] = ' ';
memcpy((char*)szTemp[amount++], &pszSource[j], i - j);
j = i + 1;
}
}
*pAmount = amount;
return szTemp;
}
void main()
{
char szSource[] = "111|222|333|444|555|666|777";
printf("Source: %sn", szSource);
unsigned int amount = 0;
char **szSection = Split(szSource, '|', &amount);
unsigned int i = 0;
for (; i amount; i++) {
printf("Section[%d]: %sn", i, szSection);
free(szSection);
}
free(szSection);
return;
}
楼主 2015-11-26 14:25 回复
Copyright © 2010~2015 直线网 版权所有,All Rights Reserved.沪ICP备10039589号
意见反馈 |
关于直线 |
版权声明 |
会员须知