Code:
scanf("%s",&z);
This statement will lead illlegle memory access also.