指针实现字符串去重逆序
新手求助:使用指针实现字符串的逆序和去重
程序代码:
#include <stdio.h> #include <string.h> void delete_(char *);//删除重复 void reverse(char *);//逆序 int main(void) { return 0; } void delete_(char *str) { size_t lenth = strlen(str); size_t i = 1, j = 1, k = 0; for (; i < lenth; k = 0, i++) { while (k < i && str[i] != str[k]) k++; if (k == i) str[j++] = str[i]; } str[j] = '\0'; } void reverse(char *str) { for (size_t i = 0, lenth = strlen(str); i < lenth / 2; i++) { char temp = str[i]; str[i] = str[lenth - i - 1]; str[lenth - i - 1] = temp; } }
[此贴子已经被作者于2019-3-6 15:19编辑过]