文字列AAbbCCがあります。必要なのは、最初の2つをコピーして配列に追加し、次に真ん中の2つをコピーして配列に追加し、最後に最後の2つを配列に追加することです。
これが私がすることです:
char color1[2];
char color2[2];
char color3[2];
strncpy(color1, string, 2); // I take the first two characters and put them into color1
// now I truncate the string to remove those AA values:
string = strtok(string, &color1[1]);
// and when using the same code again the result in color2 is bbAA:
strncpy(color2, string, 2);
それはそれらのbbを渡しますが、前のものからのAAも渡します..配列には2つの場所しかありませんが、strtolを使用すると、私が探している187ではなく大きな値が得られます..それを取り除く方法?またはそれを他の方法で機能させる方法は?何かアドバイスをいただければ幸いです。