your scanf(); might have fault... %ld should have been used. Check with that.