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

Command run not printing certain special characters #48

Open
daxida opened this issue Mar 17, 2024 · 0 comments
Open

Command run not printing certain special characters #48

daxida opened this issue Mar 17, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@daxida
Copy link
Collaborator

daxida commented Mar 17, 2024

CG has a useful way to give feedback upon printing uninitialized (is it?) memory, but locally there is no way of knowing, and the STDOUT message seems to contain no mistakes (since the the characters are not printed / are zero width).

Link of the contribution where this was tested.

C code used:

#include <stdio.h>

int main() {
    int N;
    scanf("%d", &N);
    
    for (int i = 0; i < N; i++) {
        char num[15 + 1];
        scanf(" %[^\n]", num);

        int ptr = 0;
        int minus = 0;
        while (ptr < 15 && num[ptr] == '0' || num[ptr] == '+' || num[ptr] == '-') {
            if (num[ptr] == '-') {
                minus += 1;
            }
            ptr++;
        }

        if (minus % 2) printf("-");
        for (int i = ptr; i < 15; i++) {
            // This ends up printing uninitialized memory ???
            printf("%c", num[i]);
            // fprintf(stderr, "%d\n", num[i]);
        }
        printf("\n");
    }

    return 0;
}

image
image

@daxida daxida added the bug Something isn't working label Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant