我怎样才能 "reset" \n 对齐以便打印在第一行对齐?

How can I "reset" the \n alignment in order to print aligned at the first line?

此函数必须打印单人纸牌游戏的纸牌堆。

void print_stacks(Stack *stacks){
    char moretab[20] = {0};
    Stack *currentPtr = &(stacks[0]);
    for (size_t i=1;i<10;++i){
        while (currentPtr != NULL){
            printf("%s%s\n%s",currentPtr->cardd.face,currentPtr->cardd.suit,moretab);
            currentPtr = currentPtr->nextPtr;
        }
        strcat(moretab,"\t");
        currentPtr = &(stacks[i]);
    }
}

如果需要,这里是完整的代码:https://hastebin.com/iguteleqiq.cpp

例如我有这个输出:

> cmd /c .\"solitaire.exe" 

8♣

        2♣
        Q♣

                9♠
                2♦
                2♥

                        Q♥
                        6♠
                        7♠
                        J♥

                                Q♦
                                10♦
                                7♦
                                J♦
                                4♣

                                        K♦
                                        4♠
                                        2♠
                                        A♥
                                        3♣
                                        J♣

                                                9♥
                                                3♦
                                                8♠
                                                10♥
                                                K♠
                                                3♠
                                                8♥

                                                        A♣
                                                        A♦
                                                        8♦
                                                        J♠
                                                        9♣
                                                        4♥
                                                        9♦
                                                        5♥

                                                                K♣
                                                                6♦
                                                                A♠
                                                                3♥
                                                                4♦
                                                                K♥
                                                                5♠
                                                                10♠
                                                                5♣

预期输出:

> cmd /c .\"somerset.exe" 
8♣      2♣      9♠      Q♥      Q♦        etc etc etc
        Q♣      2♦      6♠      10♦
                2♥      7♠      7♦
                        J♥      J♦
                                4♣

我怎样才能让所有这些卡片堆在同一行的第一行?我试图刷新标准输出,但没有用。我该怎么做才能实现这一目标?我不是很有经验。

正如@JohnBollinger 在评论中建议的那样,您需要逐行打印数据。堆栈是列,因此您需要跟踪您在 9 个不同堆栈中的位置。如果您有一个由 9 个堆栈指针组成的数组,这些指针初始化为 9 个堆栈的顶部,您可以遍历这 9 个指针并打印每个堆栈中的当前项以形成一行。然后循环直到没有东西可以打印。

像这样:

// you need to #include <stdbool.h> or change finished to an int
void print_stacks(Stack *stacks){
    // make 9 stack pointers
    Stack *currentPtr[9];
    // point them to the first 9 stacks
    for (size_t i=0;i<9;++i){
        currentPtr[i] = &(stacks[i]);
    }
    // loop through printing one row at a time
    bool finished;
    do{
        finished=true;
        // print the current item from each of the 9 stack pointers
        for (size_t i=0;i<9;++i){
            if (currentPtr[i] != NULL){
                printf("%s%s",currentPtr[i]->cardd.face,currentPtr[i]->cardd.suit);
                currentPtr[i] = currentPtr[i]->nextPtr;
                // we printed something so we aren't finished
                finished=false;
            }
            printf("\t");
        }
        printf("\n");
    // loop until we are finished
    } while (!finished);
}

在线试用:https://onlinegdb.com/SyPZoqcBw