大哥 你这是c语言吗 怎么都看不懂
追答额,你这#C。。。我还以为是C#呢,C语言的代码如下即可:
#include
#include
#include
#ifndef NULL
#define NULL (0)
#endif
//查找重复的字符,如果是重复的就返回0,不重复返回1
int check_repeat(char *dst_chars, int arr_size, char target)
{
int i = 0;
for (i = 0; i < arr_size; ++i) {
if ('\0' == dst_chars[i]) {
// 如果遇到字符串结束符,说明已经没有必要再找下去了
break;
}
if (dst_chars[i] == target) {
return 0;
}
}
return 1;
}
int main(int argc, char **argv)
{
int i = 0;
int j = 0;
int str_max_len = 0;
char teststr[] = "hello,world!";
char *not_repeat_chars = NULL;
str_max_len = strlen(teststr) + 1;
not_repeat_chars = (char *)malloc(sizeof(char) * str_max_len);
if (NULL == not_repeat_chars) {
printf("memory error\n");
return 1;
}
memset(not_repeat_chars, 0, str_max_len);
j = 0;
for (i = 0; i < str_max_len; ++i) {
if (0 != check_repeat(not_repeat_chars, str_max_len, teststr[i])) {
not_repeat_chars[j++] = teststr[i];
} else {
continue;
}
}
printf("%s\n", not_repeat_chars);
free(not_repeat_chars);
not_repeat_chars = NULL;
return 0;
}