Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C by STRTOK ( 6 years ago )
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <Windows.h>
#include <math.h>

char result[100];

int STRLEN(char *s)
{
	int count = 0, i;
	while(s[++count] != '\0') { }
	return count;
}

char* STRTOK(char *main, char *sub)
{
	int idx = 0, pos, check = 0;
	int length_main = STRLEN(main), length = STRLEN(sub) - 1;
	if(main != NULL)
	{
		for(int i = 0; i < length_main; i++)
		{
			check = 0;
			if(main[i] == sub[0])
			{
				pos = i + length;
				break;
			}
			result[idx++] = main[i];
		}
	}
	else if(main == NULL || main == 0)
	{
		for(int i = pos + 1; i < length_main; i++)
		{
			if(main[i] == sub[0])
			{
				pos = i + length;
				break;
			}
			result[idx++] = main[i];
		}
	}
	result[idx] = '\0';
	return result;
}

int main()
{
	char s1[] = "Dung, Hoa, Hoang, Linh";
	char *s2;
	char s3[3] = ", ";
	s2 = STRTOK(s1, s3); // cái này e đã làm được (còn cái null thi e chưa thể làm ra được nhờ a cho e thêm gợi ý)

	//while(s2 != NULL)
	//{
	//	printf("%s\n", s2);
	//	s2 = strtok(NULL, s3);
	//}
	printf("%s\n", s2);
	getch();
	return 0;
}

 

Revise this Paste

Your Name: Code Language: