指针函数字符串

时间:2016-01-03 18:29:07
【文件属性】:

文件名称:指针函数字符串

文件大小:52KB

文件格式:PDB

更新时间:2016-01-03 18:29:07

char×

#include #include int reduce(int a,int b); int add(int a,int b); void exercise(); int reduce(int a,int b){ return a-b; } int add(int a,int b){ return a+b; } void exercise(){ int e = 3,f = 4; int (*c)(int a,int b); c = add; int d = (*c)(e,f); printf("%d\n",d); c = reduce; d = (*c)(e,f); printf("%d\n",d); } void exercise_two(); void exercise_two(){ char str[100]; printf("请输入字符串\n"); scanf("%s",str); //去掉重复的字符 char *ss = str; //char *i = ss+1; //printf("%c\n",*i); for(char *i = ss; *i != '\0';i++){ for(char *j = i+1; *j != '\0';j++){ if(*i == *j){ strcpy(j,j+1); j--; } } } printf("\n"); puts(str); } void exercise_three(); void exercise_three(){ char str[100]; printf("请输入字符串\n"); scanf("%s",str); //去掉重复的字符 char *ss = str; int nums[128] = {0}; /* for(int i = 0;i < 256;i++){ printf("%c",i); } */ char *s2 = str; while(*ss++ != '\0'){ if(nums[(int)*ss] == 0){ nums[(int)*ss] = 1; s2 = s2+1; *s2 = *ss; } } *s2 = '\0'; printf("%s\n",str); } exercise_four(); exercise_four(){ char str[100]; printf("请输入字符串\n"); scanf("%s",str); //去掉重复的字符 char *ss = str; int nums[128] = {0}; } int main() { exercise_four(); //exercise_three(); //exercise_two(); //exercise(); return 0; }


网友评论