1 #include2 #include 3 /* 4 1.以字符串作为参数 5 2.找出ASCII在1~127范围内的字符 6 3.去掉重复字符 7 */ 8 9 int GetString(char *str);10 11 int main(int argc, char *argv[])12 {13 char ch[] = "abcd123123123123123123";14 int num = 0;15 16 num = GetString(ch);17 18 printf("num = %d\n", num);19 return 0;20 } 21 22 int GetString(char *str)23 {24 /*第一步:先计算符合范围的ASCII*/25 unsigned int index;26 unsigned int n = 0;27 unsigned int i = 0, j, k = 0; 28 char flag; 29 char arr[strlen(str)];30 char newchar[strlen(str)];31 32 for(index = 0; index < strlen(str); index++)33 {34 if((str[index] >= 0) && (str[index] <= 127))35 {36 arr[n] = str[index];37 n++;38 } 39 } 40 41 while(arr[i] != '\0') 42 { 43 flag = 1; 44 for(j = 0; j < i; j++) 45 { 46 if(arr[i] == newchar[j]) 47 {48 flag = 0; 49 } 50 } 51 if(flag) 52 {53 newchar[k] = arr[i];54 k++;55 }56 57 i++; 58 } 59 60 newchar[k]='\0'; 61 puts(newchar); 62 63 return k;64 }