#include "stdio.h" void del(char a[],char c){ int i,j; for(i=0;a[i]!='\0';i++){ if(a[i]==c){ for(j=i;j<strlen(a);j++){ a[j]=a[j+1]; } } } } char *del2(char *str,char c){ char *p=str; while(*p){ if(*p!=c){ *str++=*p; } p++; } *str='\0'; return p; } void reverse2(char *str){ char *pre=str+strlen(str)-1; while(str!=pre){ char c=*str; *str=*pre; *pre=c; str++; if(str==pre) break; else pre--; }
} int main(){ char str[]="abcdaef"; reverse2(str); printf("%s\n",str); del2(str,'c'); printf("%s\n",str); }
|
del函数删除指定字符,reverser反转字符串
阅读(382) | 评论(0) | 转发(0) |