c++ - Access violation when pointer is not pointing to NULL -
This small code is facing rum time error, which is saying "login violation". I have read about it online, which says that when an indicator is pointing to the tap, its value can not be changed. But did not solve that problem The code dump occurs because you are reaching an indicator that does not start has been done. To begin a "current" one valid memory space, it must start before de-referencing. The more cleaner code will be Includes # lt; Iostream & gt; using namespace std; Int max = 3; Structure node {char * ptr; } * Start, * start = start; Zero init () {current-> gt = ptr = (char *) malloc (max * sizeof (char)); // Error in this line} Add zero (four pages) {char * c; C = current-> Ptr; If (page == * c) COAT & lt; & Lt; "Yes"; And cout & lt; & Lt; "No"; } Zero main () {init (); Add one '); Cin & gt; & Gt; Maximum; }
#include & lt; Iostream & gt; using namespace std; Int max = 3; Structure node {char * ptr; }; Structure node * start = new node (); Struct node * current = start; Zero init () {current-> gt = ptr = (char *) malloc (max * sizeof (char)); // Error in this line} Add zero (four pages) {char * c; C = current-> Ptr; If (page == * c) COAT & lt; & Lt; "Yes"; And cout & lt; & Lt; "No"; } Zero main () {init (); Add one '); Cin & gt; & Gt; Maximum; }
Comments
Post a Comment