Your scanf() usage is incorrect. scanf() takes pointers, not values. In other words, it should be:
Code:
scanf("%d\n", &type);