Removing the C language character string repeat

Write a function to remove a character string repeat, such as the "goole" turned into "gole"

char * str_uniq(char* str)
{
	int i = 0;
	int j = 0;
	int k = 0;
	while(str[i] != '\0')
	{
		j = i + 1;
		while(str[j] != '\0')
		{
			if(str[i] == str[j])
			{
				k = j;
				while(str[k] != '\0')
				{
					str[k] = str[k+1];
					k++;
				}
				str[k] = '\0';
				j--;
			}
			j++;
		}
		i++;
	}
	return str;
}

int main(void)
{
	char str[] = "goolegoole";
	str_uniq(str);
	printf("%s\n", str);	//gole
	return 0;
}
Published 50 original articles · won praise 5 · Views 1539

Guess you like

Origin blog.csdn.net/qq_42483691/article/details/104332124