• 0
Votes
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 195

Backtrace:

File: /home/u125378470/domains/lawhelpguru.org/public_html/application/views/question.php
Line: 195
Function: _error_handler

File: /home/u125378470/domains/lawhelpguru.org/public_html/application/controllers/Questions.php
Line: 416
Function: view

File: /home/u125378470/domains/lawhelpguru.org/public_html/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Visual C++ assert- String subscript out of range

<button aria-describedby="--stacks-s-tooltip-hpga6rpa" aria-label="Bookmark" aria-pressed="false" class="js-bookmark-btn s-btn s-btn__unset c-pointer py4 js-gps-track" data-controller="s-tooltip" data-gps-track="post.click({ item: 1, priv: 0, post_type: 1 })" data-s-tooltip-placement="right" data-selected-classes="fc-yellow-600"></button><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" height="18" viewbox="0 0 19 18" width="19"></svg>

 

My program is a solution for the Day 6 question in Advent of Code 2015. I get an error when I use "Start Without Debugging" and enter the puzzle input in the output window.The image contains the exact error I received. The error is related to "string subscript out of range". I would like help in resolving this error.

const int r = 1000;//global variable
const int c = 1000;//global variable
int lights[r][c];//global array

void instruction(string inp)//extracting OFF, ON, or toggle indication from the instruction
{
    int* loc;
    int coord[4] = { 0 };
    char cond = inp[7];
    loc = &coord[3];

    switch (cond)
    {
    case 'f':
        coordinates(loc, inp);
        execute(coord, cond);
        break;
    case 'n':
        coordinates(loc, inp);
        execute(coord, cond);
        break;
    default:
        coordinates(loc, inp);
        execute(coord, cond);
        break;
    }
}

void coordinates(int* loc, string inp)//extracting coordinates from the instruction
{
    int i, k = 0, l;
    l = inp.length()-1;
    for (i = l; inp[i] != ','; i--)
    {
        *loc += (inp[i]-'0') * pow(10,k);
        k++;
    }
    i--;
    loc--;
    k = 0;
    for (; inp[i] != ' '; i--)
    {
        *loc += (inp[i]-'0') * pow(10,k);
        k++;
    }
    i = i - 9;
    loc--;
    k = 0;
    for (; inp[i] != ','; i--)
    {
        *loc += (inp[i]-'0') * pow(10,k);
        k++;
    }
    i--;
    loc--;
    k = 0;
    for (; inp[i] != ' '; i--)
    {
        *loc += (inp[i]-'0') * pow(10,k);
        k++;
    }
}

void execute(int coord[], char cond)
{
    int i, j;
    for (i = coord[0]; i <= coord[2]; i++)
    {
        for (j = coord[1]; j <= coord[3]; j++)
        {
            if (cond == 'f')
                lights[i][j] &= 0;
            else if (cond == 'n')
                lights[i][j] |= 1;
            else
                lights[i][j] = ~lights[i][j];
        }
    }
}

int main()
{
    int i, j, k, count = 0;
    string inp;

    for (i = 0;;i++)
    {
        cout << "Enter an instruction" << endl;
        cin >> inp;

        if (inp != "xx")//To manually move to counting the number of lights turned ON
            instruction(inp);
        else
        {
            for (j = 0; j < r class="hljs-keyword">for (k = 0; k < c class="hljs-keyword">if (lights[j][k])
                        count++;
                }
            }
            cout << endl << "Number of lights lit " << count class="hljs-keyword">break;
        }
    }
    return 0;
}