無限スプリット

自作 Split関数

かなり大叩きしましたっ!


#include 
#include 

char* SplitStr(char *str, int *start);

int main(void)
{
	char *str = "1,teru,koneko,2019,06,01";

	char result[64 + 1];

	int start = 0;

	while(start < strlen(str))
	{
		strcpy(result, SplitStr(str, &start));
		printf("%s\n", result);
	}

	return 0;
}

char* SplitStr(char *str, int *start)
{
	char result[64 + 1];
	char *po = result;
	int i = *start;
	int j = 0;

	while(',' != str[i])
	{
		result[j] = str[i];

		if(i > strlen(str))
			break;

		i++;
		j++;
	}

	result[j] = '\0';

	*start = ++i;

	return po;
}