0

これらは機能です

//printList for Debugging
void printList(letterListT *head){
    letterListT *temp = head;
    while(temp != NULL){
        printf("%c ", temp->letter);
    temp = temp->nxt;
    }
}  

//Add the Specified Letter by Creating a New Node in the Letter List defined
void addLetter(letterListT *letListHead, char letter){
    letterListT *newNode;
    newNode = (letterListT *)malloc(sizeof(letterListT));

    newNode->letter = letter;

    newNode->nxt = letListHead->nxt;
    letListHead->nxt = newNode;
}

そしてこれらは主にあります:

unusedLetList = (letterListT *)malloc(sizeof(letterListT));
unusedLetList->nxt = NULL;

for(i=122; i>=97; i--){ //ascii codes for z to a
addLetter(unusedLetList, i);
}

//printlists Test
printList(unusedLetList);

これが出力です...

p a b c d e f g h i j k l m n o p q r s t u v w x y z 

私の質問は...この「p」はどこから来たのですか?!

4

1 に答える 1

5

リストヘッドノード。

unusedLetList = (letterListT *)malloc(sizeof(letterListT));
unusedLetList->nxt = NULL;

ここでヘッドノードを作成し、ヘッドノードの後に​​各文字を追加します。ヘッドノードには初期化されていない->letterフィールドがあります。それは何でもかまいません。たまたまpです。

于 2012-12-16T21:49:39.517 に答える