[問題]C 字串比較與輸出
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
VS2013
問題(Question):
請問要如何做字串內容的比較與刪減 例如有兩字串123 245
希望可以比較過兩字串之後把兩串中重複的字刪除並合併
餵入的資料(Input):
目前寫的結構跟字串是長這樣
struct MyStruct{
char *number1;
char *number2;
char *number3;
}
typedef struct MyStruct MS
void main(){
MS c[2];
c[0].number1="1";
c[0].number2="2";
c[0].number3="3";
c[1].number1="2";
c[1].number2="4";
c[1].number3="5";
}
合併的部分已經做完了 目前可以把兩字串合併 但是不知道要怎麼比較跟刪除重複
char* MSarray_total(MS *arr,int size){
const int strSize=100;
char *str=new char[strSize];
str[0]='\0';
int i;
for (i=0;i<size,i++){
stract_s(str,strSize,arr[i].number1);
stract_s(str,strSize,arr[i].number2);
stract_s(str,strSize,arr[i].number3);
}
return str;
}
預期的正確結果(Expected Output):
目前輸出會是 123245
希望可以輸出成12345(重複的只顯示一次)
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.240.28.1
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1473579791.A.77E.html
推
09/11 17:00, , 1F
09/11 17:00, 1F
→
09/11 17:00, , 2F
09/11 17:00, 2F
→
09/11 17:30, , 3F
09/11 17:30, 3F
→
09/11 17:30, , 4F
09/11 17:30, 4F
→
09/11 19:42, , 5F
09/11 19:42, 5F
推
09/11 21:34, , 6F
09/11 21:34, 6F
→
09/11 21:36, , 7F
09/11 21:36, 7F
→
09/11 21:37, , 8F
09/11 21:37, 8F
→
09/11 21:38, , 9F
09/11 21:38, 9F
推
09/12 12:25, , 10F
09/12 12:25, 10F
推
09/12 14:52, , 11F
09/12 14:52, 11F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章