i keep getting Process returned -1073741819 (0xC0000005) whats the reason?

Pages: 12
fixed version:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <cmath>
        #include <stack>
        #include<queue>
        #include <iostream>
        #include <regex>
         #include <vector>
        #include <thread>
         #include <bitset>

     #include <ctime>

     #include <string.h>

     #include <math.h>
    #include <bits/stdc++.h>

     #define M_PI 3.14159265358979323846264338327950288419716939937510582097494

     #include<windows.h>
    #define gkey GetAsyncKeyState
     using namespace std;
    #define rxs regex_search
    #define loop while(true)
    double a;
    double num1;
     double c3 = 299792458;
     double c3sq = 89875517873681764;
     int mc;
         string again;

     stack<int> presedence;
     stack<string> oprators;
     queue<double> numbers;
     stack<char> test;
     double num5;
     double num6;
     int E;
     int abrt = 0;
     double num2;

     double ans = num1 + num2;
     int num;
     int numalt = 0;
     int numaltt = 0;
     //int nums [] = {srand(time(0));rand();}

    bool autoregex(string test){
        regex e ("[-+]?([0-9]*\.[0-9]+|[0-9]+)");
       if (regex_match (test,e))
            return true;

        return false;
    }
    bool autrege(string test){
        regex aret("SIN|LOG|sqrt|sin|log|tan|pi|e|ln|EE|[^0-9a-z$@#&\]");
                   if (regex_match (test,aret)){
                    return true;
                   }
    else{
        return false;}
                   }
                   void namehere(string test){
    if(autrege(test) == true){
    regex bret("[+-]");
    regex cret("[/*xX]");
    regex dret("SIN|LOG|sqrt|sin|log|tan|pi|!|e|ln|EE|\\^");
    regex omega("\\)");
    regex canmae("\\(");
    if (regex_match (test,bret)){num2 = 1;};
    if (regex_match (test,cret)){num2 = 2;};
    if (regex_match (test,dret)){num2 = 3;};
    if (regex_match (test,omega)){num2 = 4;numaltt = numaltt + 1;};
    if (regex_match (test,canmae)){num2 = 4;numalt = numalt + 1;};

    }




                   }

    int main()
    {
    vector<double> vec;
        again = "n";

     while(again == "n"&&abrt == 0){
     // queue<double> numbers; stack<int> pres;
            queue<string> output;
       int test;
     string name;
       getline(cin, name);
       istringstream iss(name);
     string token;
        while(iss >> token)
        {
          if(autoregex(token) == true){
                output.push(token);
          }
          if(autrege(token)== true)//token area
          {


              namehere(token);
            if( !presedence.empty() && num2 == presedence.top())
            {
                output.push(oprators.top());
                oprators.pop();
                oprators.push(token);
                presedence.pop();
                presedence.push(num2);

            }
           while(presedence.empty() == 1 && oprators.empty() == 1)
            {
                presedence.push(num2);
                oprators.push(token);
           }
           while(!presedence.empty() && presedence.top() < num2 )
            {
            oprators.push(token);
            presedence.push(num2);

           }

           while( !presedence.empty() && presedence.top() > num2 )
           {
            output.push(oprators.top());
            oprators.pop();
            presedence.pop();
             oprators.push(token);
            presedence.push(num2);
           }
    //3-T 2-ME
          }

    }
    while(presedence.empty() != 1 && oprators.empty() != 1){  output.push(oprators.top());
    oprators.pop();presedence.pop();}
    while(!output.empty()){cout<<output.front()<<", ";output.pop();








    }

    }


    while(again != "n"&&abrt == 0){

    }


    }
Last edited on
It means your program crashed with an ACCESS_VIOLATION exception :-O

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/596a1078-e883-4972-9bbc-49e60bebca55

This indicates you are trying to access an "invalid" memory address. For example, this can be the result of an array out-of-bounds access, trying to dereference a dangling pointer, and so on...

💡 Time to run your program in the debugger and track down where exactly the crash occurs!
Last edited on
im not using arrays? or pointers, just stacks
An "access violation" can be pretty much anything that somehow ends up accessing an invalid address.

I just was giving some common examples.

Trying to access an element beyond index size()-1 of an std::vector or std::queue is "undefined behavior" and could trigger an access violation just as well. So that's yet another possibility.

(same for calling pop() or front() on an empty std::queue)

💡 Anyhow, instead of guessing, please use the debugger to figure out where exactly it is crashing!
Last edited on
vector in code, can go [] out of bounds on those. .at() is slow and checks, [] is fast and does not.
string as well, string has an (array, vector, etc [] operator)
things like this are what to look for.
The program you posted is incomplete and does not compile.
i fixed it
im not using arrays? or pointers, just stacks

Hmmmm, std::vector is a sequence container that encapsulates dynamic size arrays.

A regular array is a sequence container, so yeah, you are using arrays. An array you could be going out of bounds when accessing elements.

Hmmmm, std::queue is a container adaptor, a wrapper usually around a std::list.

std::lists are sequence containers that allow constant time insert and erase operations anywhere within the sequence, and iteration in both directions.

There's that "sequence container" designation again. Random access of a std::list's elements isn't possible, it is a different interface of a sequential container.

Hint, hint an array with different ways to access the elements.

You say you are using a stack? A std::stack and a std::queue are two different containers, how the elements are accessed is pretty much the key differences. LIFO vs. FIFO.

You are using std::queue.

I see variables and what could be functions used in main without seeing where they are instantiated or defined. again, abrt, namehere, presedence, oprators are what stand out with a cursory read through, there may be others.

Your formatting is not consistent, that certainly doesn't help reading and understanding your code.

Code that isn't SSCCE, a Short, Self Contained, Correct (Compilable), Example.
http://www.sscce.org/

I certainly don't want to spend time adding bits and pieces of code to get this to work, such as including <header> files. Bits and pieces I could get wrong.
i fixed it

It would be nice for others if you told us what exactly was the problem and how you fixed it.

There is nothing more frustrating than finding a forum thread that discusses exactly the same problem you have (or a very similar problem) but then the resolution is missing ;-)
Last edited on
@kigar64551 doesn't matter bug came up again :-(
doesn't matter bug came up again :-(

As mentioned two times before, unless you run the program in a debugger and make a proper stack trace when the crash occurs, you probably won't make any progress in tracking down the cause...

https://en.wikipedia.org/wiki/Debugger

Are you using an IDE, such as Visual Studio? If so, it should be trivial to run in "debug" mode.
Last edited on
@kigar64551 I am running it in debug mode, build logs don't offer any help tho, ide is codeblocks
build logs don't offer any help tho, ide is codeblocks

I'm not talking about "build logs" – though compiler warnings can be very helpful too; don't ignore them 😏

If you actually run the program in the debugger, then as soon as an exception (e.g. "access violation") is thrown, the program won't simply die and leave you clueless. Instead, the debugger will "freeze" the execution at that point and you will be able see the stack trace, so that you can pinpoint where exactly it crashed. Of course, you can also manually "pause" the program, inspect variables, set break points, and so on...

💡 Learn how to use the debugger, or you probably won't get far!

Please watch this:
https://www.youtube.com/watch?v=h_r5ZfETRZQ
Last edited on
@kigar64551 not useful: just gives me [Inferior 1 (process 6440) exited with code 030000000005]
Debugger finished with status 0
doesn't say which line it crashes at
Last edited on
> The program you posted is incomplete and does not compile.

+1

You need to have escape sequences for special characters.
For example, since \ must be escaped in C++ too:
regex: [-+]?([0-9]*\.[0-9]+|[0-9]+)
C++: "[-+]?([0-9]*\\.[0-9]+|[0-9]+)"
Or use raw string literals: https://www.stroustrup.com/C++11FAQ.html#raw-strings
@JLBorges added the compilable code, I am not trying to escape \ as a special letter also I think I've got a rough idea of whats causing the error:
1
2
3
4
5
6
while(presedence.top() >= num2)
           {
            output.push(oprators.top());
            oprators.pop();
            presedence.pop();
           }
it seems that adding the = causes a stack overflow, but I can't seem to get why it causes the stack overflow, I've gone through the code step by step, but I just cant see why it overflows
Last edited on
@OP,

why don't you post the code that compiles and runs?
Before you do a .pop() or .top(), you should check that the container is not empty.
while (presedence.top() >= num2) It crashes because the stack is empty.
codinglexernewbie wrote:
not useful: just gives me [Inferior 1 (process 6440) exited with code 030000000005]
Debugger finished with status 0
doesn't say which line it crashes at

Be sure your debugger is configured to break (pause execution) on all exceptions/signals.

Having said that, an illegal memory access results in undefined behavior. If you are lucky, this means that your program crashes right away and you can find the crash site. In the worst case, though, the application may just continue to run and read some "garbage" data and/or overwrite some unrelated data 😱

(Furthermore, there is no guarantee that you get the exactly same "erroneous" behavior on every run)


For debugging "memory errors", tools like Valgrind , AddressSanitizer (ASAN) or Dr. Memory are useful!

https://valgrind.org/docs/manual/mc-manual.html

https://drmemory.org/index.html

https://clang.llvm.org/docs/AddressSanitizer.html

(AFAIK, Valgrind is Linux-only, but definitely worth a look! Dr. Memory works on Windows too)


seeplus wrote:
Before you do a .pop() or .top(), you should check that the container is not empty.

+1

(actually it must always be ensured that the container is not empty before top() or pop() is called)
Last edited on
Pages: 12