重複の可能性:
リンクリストに個別の単語を保存する
1つのリンクリストから単語を読み取るコードを書き込もうとしています。
次に、固有の単語を特定し、その単語を別のリンクリストに保存します。
残念ながら、コードは機能していません。この問題を解決するにはヘルプが必要です。
これは私がこれまでに得たものです、私はそれが役立つことを願ってコメントを追加しました。
struct list {
char string[50];
struct list *next;
};
list *header;
list *next = NULL;
struct distinct {
char string[50];
struct distinct *dnext;
};
distinct *track;
distinct *dnext;
void checkdistinct() {
int dwcheck = 0; //as boolean to check whether distinct word is found
list *ori; //first struct
ori = header->next;
distinct *copy; //second struct
distinct *check = NULL;
track = (distinct*)malloc(sizeof(distinct));
track->dnext=NULL;
copy = track;
if(copy == track) { // direct copy first time
strcpy(copy->string, ori->string);
}
else {}
while(ori->next!=NULL) { // while original struct did not end
check = track;
while(check->dnext != NULL) { //check end when second list ends
if(strcmp(ori->string, check->string)!=0) {
check = check->dnext;
}
else if(strcmp(ori->string, check->string)==0) {
dwcheck = 1;
ori = ori->next; // original list will move one node next
check = check->dnext; // check pointer continues
}
}
copy->dnext = (distinct*)malloc(sizeof(distinct)); // new node for new word
copy = copy->dnext;
if(dwcheck != 1) { // when boolean = false, original will move one node next, next word will be copied
ori = ori->next; // as the node is moved one node (above) when boolean = true
}
else if(dwcheck == 1) {
strcpy(copy->string, ori->string);
}
dwcheck = 0; // reset
copy->dnext=NULL; // set not copied node as NULL each time
check = NULL; // reset
}
}
私の最初のリスト:こんにちは私の名前はスーパーマンです
私の2番目のリスト:こんにちは私の名前名<-残り
悪いコーディングで申し訳ありませんが、まだ新人です。ありがとう!