I recommend you replace hardcoded integer values with constants and if->if->if by switch construction. It makes code more readable. Also, why do not use the same status for error cases (1)?