TOPIC

Runtine Error in C

Andel Vitório asked 2 months ago

Alguém poderia me explicar o porquê de resultar me Runtine Error? Já tentei mts soluções, mas nada.

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

#define MAXS 50

int main()
{
    char *end = (char *)malloc(MAXS * sizeof(char));
    char str[MAXS];

    while(scanf(" %s", str) != EOF)
    {
        char r[MAXS], l[MAXS], j[MAXS];
        int pos = 0, idx = 0;

        while(str[pos++] != '+')
            r[idx++] = str[pos-1];
        r[idx] = '\0', idx = 0;

        while(str[pos++] != '=')
            l[idx++] = str[pos-1];
        l[idx] = '\0', idx = 0;

        while(str[pos++])
            j[idx++] = str[pos-1];
        j[idx] = '\0';

        if(!strcmp(r, "R")) printf("%lld\n", strtoll(j, &end, 10) - strtoll(l, &end, 10));
        else if(!strcmp(l, "L")) printf("%lld\n", strtoll(j, &end, 10) - strtoll(r, &end, 10));
        else if(!strcmp(j, "J")) printf("%lld\n", strtoll(l, &end, 10) + strtoll(r, &end, 10));
    }
}

This topic has not been answered yet. Be the first!

Remember not post solutions. Your post may be reviewed by our moderators.