Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSTD: noarch.Printf wrong printFormat #551

Closed
Konstantin8105 opened this issue Jan 11, 2018 · 0 comments
Closed

CSTD: noarch.Printf wrong printFormat #551

Konstantin8105 opened this issue Jan 11, 2018 · 0 comments

Comments

@Konstantin8105
Copy link
Contributor

Konstantin8105 commented Jan 11, 2018

/*
 * Prints out a grid of the order with which the Knight moved.
 */
void printSteps() {
    int stepsAmount = sizeX*sizeY;
    int magnitude = lengthInt(stepsAmount);
    
    char printfFormat[30] = "%0";
    char magnitudeString[10];
    
    /*
     * printfFormat = "%0Xd\n"
     * X is the number of digits that the largest step contains
     * Used to print out leading 0's so the grid stays aligned
     */
    
    sprintf(magnitudeString, "%d", magnitude);
    strcat(printfFormat, magnitudeString);
    strcat(printfFormat, "d  ");
     
    for(int x = 0; x < sizeX; x++) {
        for(int y = 0; y < sizeY; y++) {
            printf(printfFormat, *(steps + y*sizeX + x) + 1);
        }
        printf("\n");
        printf("\n");
    }

    printf("\n");
}
// printSteps - transpiled function from file : king.c , line : 309
/*
 * Prints out a grid of the order with which the Knight moved.
 *//*
 * printfFormat = "%0Xd\n"
 * X is the number of digits that the largest step contains
 * Used to print out leading 0's so the grid stays aligned
 */func printSteps() {
        var stepsAmount int = sizeX * sizeY
        var magnitude int = lengthInt(stepsAmount)
        var printfFormat []byte = []byte("%0\x00")
        var magnitudeString []byte = make([]byte, 10, 10)
        noarch.Sprintf(magnitudeString, []byte("%d\x00"), magnitude)
        noarch.Strcat(printfFormat, magnitudeString)
        noarch.Strcat(printfFormat, []byte("d  \x00"))
        {
                var x int = 0
                for ; x < sizeX; func() int {
                        x += 1
                        return x
                }() {
                        {
                                var y int = 0
                                for ; y < sizeY; func() int {
                                        y += 1
                                        return y
                                }() {
                                        noarch.Printf(printfFormat, steps[(0+y*sizeX+x)]+1)
                                }
                        }
                        noarch.Printf([]byte("\n\x00"))
                        noarch.Printf([]byte("\n\x00"))
                }
        }
        noarch.Printf([]byte("\n\x00"))
}

Result:

%!(NOVERB)%!(EXTRA int=1)%!(NOVERB)%!(EXTRA int=16)%!(NOVERB)%!(EXTRA int=19)%!(NOVERB)%!(EXTRA int=26)%!(NOVERB)%!(EXTRA int=3)%!(NOVERB)%!(EXTRA int=10)

%!(NOVERB)%!(EXTRA int=18)%!(NOVERB)%!(EXTRA int=25)%!(NOVERB)%!(EXTRA int=2)%!(NOVERB)%!(EXTRA int=9)%!(NOVERB)%!(EXTRA int=20)%!(NOVERB)%!(EXTRA int=27)

%!(NOVERB)%!(EXTRA int=15)%!(NOVERB)%!(EXTRA int=8)%!(NOVERB)%!(EXTRA int=17)%!(NOVERB)%!(EXTRA int=24)%!(NOVERB)%!(EXTRA int=11)%!(NOVERB)%!(EXTRA int=4)

%!(NOVERB)%!(EXTRA int=30)%!(NOVERB)%!(EXTRA int=23)%!(NOVERB)%!(EXTRA int=6)%!(NOVERB)%!(EXTRA int=13)%!(NOVERB)%!(EXTRA int=28)%!(NOVERB)%!(EXTRA int=21)

%!(NOVERB)%!(EXTRA int=7)%!(NOVERB)%!(EXTRA int=14)%!(NOVERB)%!(EXTRA int=29)%!(NOVERB)%!(EXTRA int=22)%!(NOVERB)%!(EXTRA int=5)%!(NOVERB)%!(EXTRA int=12)

Need for #67

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant