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 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; }

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

  #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

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -