1 / 3
Sep 2021

Hello,

I have just submitted my first code and the judge rejected it because of an execution error (SIGABRT). But when I click on my orange rank, it sends me back to the page with “Accepted Test!” And the expected output is the same as my own solution. And when I compile on IDEONE, it works too.

Do you know what happened?

Here is the code in case that would be useful. The problem is CPTTRN1 - Character Patterns (Act 1)7

#include <stdlib.h>
#include <stdio.h>

#define xstr(s) str(s)
#define str(s) #s

#define DIGITS 2
#define DIM_PER_CHESS 2


int * saveInput(int * t) {
    if(scanf(" %"xstr(DIGITS)"d", t) == 0) return NULL;
    int * allDim = (int *)calloc(*t, sizeof(int));
    if(allDim == NULL) return NULL;

    int i;
    for(i=0; i<2*(*t); i++) {
        if(scanf(" %"xstr(DIGITS)"d", allDim+i) == 0) {
            free(allDim);
            return NULL;
        }
    }
    return allDim;
}


int main()
{
    int t=0;
    int * allDim=saveInput(&t);
    if(allDim == NULL) return 1;

    int chess, l, c, lines, columns;
    for(chess=0; chess<t; chess++) {
        lines=allDim[DIM_PER_CHESS*chess];
        columns=allDim[DIM_PER_CHESS*chess+1];
        for(l=0; l<lines; l++) {
            for(c=0; c<columns; c++) {
                if((l+c)%2 == 0) printf("*");
                else printf(".");
            }
            printf("\n");
        }
        printf("\n");
    }

    free(allDim);
    return 0;
}
  • created

    Sep '21
  • last reply

    Sep '21
  • 2

    replies

  • 647

    views

  • 2

    users

  • 1

    link

13 days later

allDim's length is (*t); but in the rest of the code it is assumed it has twice this length.

Yes I solved the problem after having posted it. But thanks for your reply.