The code runs normally in the turboc ++ 3.0 environment, but can be compiled successfully in the vs environment, but the input data is a bit faulty.
After the red part is modified, the code is OK under. But why did the change run normally in the turboc ++ 3.0 environment?
# Include <stdio. h>
# Include <malloc. h>
# Include <ctype. h>
Typedef struct node lnklist;
Struct Node
{
Int data;
Lnklist * next;
};
Int main (void)
{
Lnklist * Start = NULL, * P, * q, * temp;
Char OPT;
Do
{
Printf ("/n/T menu"
"/N/T 1. Create/append linked list"
"/N/T 2. Reverse linked list"
"/N/T 3. Display linked list"
"/N/T 4. Exit"
"/N enter your choice :"
);
Opt = getchar ();
Flushall ();
Switch (OPT)
{
Case '1 ':
Do
{
P = start;
While (P! = NULL & P-> next! = NULL)/* before modification, while (p-> next! = NULL )*/
{
P = p-> next;
}
Q = (lnklist *) malloc (sizeof (lnklist ));
Printf ("/nenter the data :");
Scanf ("% d", & Q-> data );
Q-> next = NULL;
If (START = NULL)
Start = Q;
Else
P-> next = Q;
Printf ("wanna continue? ");
} While (tolower (getchar () = 'y ');
Break;
Case '2 ':
P = start;
Q = p-> next;
While (Q! = NULL)
{
Temp = Q-> next;
Q-> next = P;
P = Q;
Q = temp;
}
Start-> next = NULL;
Start = P;
Break;
Case '3 ':
P = start;
Printf ("/nstart = % u", start );
While (P! = NULL)
{
Printf ("-> [% d | % u]", p-> data, p-> next );
P = p-> next;
}
Getchar ();
}
} While (OPT! = '4 ');
Printf ("/nsuccess/N ");
Return 0;
}