//退出的时候会卡
#include <iostream>
bool NotIn(char ch, char * str, char * top)
{
char * ptr;
for (ptr = str; ch != *ptr && ptr != top; ptr++)
{
}
return ptr == top;
}
int main()
{
char str[] = "An apple a day keeps the doctor away.";//去重复
char * unique_list = (char *)malloc(sizeof(strlen(str) + 1) * sizeof(char));
char * top = unique_list;
for (char * ptr = str; *ptr != '\0'; ptr++)
{
if (NotIn(*ptr, unique_list, top))
{
*top = *ptr;
top++;
}
}
*top = '\0';
for (char * ptr = unique_list; *ptr != '\0'; ptr++)
{
std::cout << *ptr;
}
free(unique_list);
return 0;
}
#include <iostream>
bool NotIn(char ch, char * str, char * top)
{
char * ptr;
for (ptr = str; ch != *ptr && ptr != top; ptr++)
{
}
return ptr == top;
}
int main()
{
char str[] = "An apple a day keeps the doctor away.";//去重复
char * unique_list = (char *)malloc(sizeof(strlen(str) + 1) * sizeof(char));
char * top = unique_list;
for (char * ptr = str; *ptr != '\0'; ptr++)
{
if (NotIn(*ptr, unique_list, top))
{
*top = *ptr;
top++;
}
}
*top = '\0';
for (char * ptr = unique_list; *ptr != '\0'; ptr++)
{
std::cout << *ptr;
}
free(unique_list);
return 0;
}