C語言-刪除重復字符


//實現對一個字符串的刪除重復的字符,並輸出刪除后的字符串,(如從”testroadeasy”中輸出”tesroady”)

Action()
{
    char *str="testroadeasy";
    char *desc;
 desc=(char *)malloc(100*sizeof(char));
 fun_delete(str,desc);
 lr_output_message("%s",desc);
 return 0;
}
int fun_delete(char *str,char *desc){
 int i;
 int len=strlen(str);
 while(*str!='\0'){
  for(i=0;i<len;i++){
   if(*str==*desc){  
 // *str!=*desc;
  str++;
 // desc++;
 // continue;
  }
 
  else{
   *desc++=*str++;
  }
  
 }
 }
 *desc='\0';
 return 0;
}
運行結果:
Action.c(7): testroadeasy


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM