I've gone through my code and I don't think the problem was really with switch(). I havent figured out what it is though. Here's the code.
Code:
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <stdlib.h>
void main(void)
{
int *p;
long result;
char code[BUFSIZ];
char station1[] = "(1) Gros Islet Station (GR)";
char station2[] = "(2) Central Police Station (CPS)";
char station3[] = "(3) Marchand Police Station (MA)";
char station4[] = "(4) La Caye Police Station (LC)";
char station5[] = "(5) Dennery Police Station (DE)";
char station6[] = "(6) Micoud Police Station (MI)";
char station7[] = "(7) Vieux Fort Police station (VX)";
char station8[] = "(8) Choiseul Police Station (CH)";
char station9[] = "(9) Soufriere Police Station (SU)";
char station10[] = "(10) Canaries Police station (CN)";
char station11[] = "(11) Anse La Raye Police Station (AN)";
char station12[] = "(12) Marigot Police Station (MB)";
char station13[] = "(13) Police Headquaters (PHQ)";
char station14[] = "(14) Criminal Investigations Department (CID)";
char station15[] = "(15) Criminal Records Office (CRO)";
char station16[] = "(16) Traffic Unit (TU)";
char station17[] = "(17) Immigration Department (IMM)";
char station18[] = "(18) Community Relations Branch (CRB)";
char station19[] = "(19) Special Branch (SB)";
char station20[] = "(20) Complaints Unit (CU)";
char station21[] = "(21) Police Motor Pool (PMP)";
char station22[] = "(22) Drug Squad (DS)";
char station23[] = "(23) Police Training School (PTS)";
char station24[] = "(24) Special Services Unit (SSU)";
char station25[] = "(25) Police Control Room (PCR)";
char station26[] = "(26) Police Marine unit (PMU)";
fputs("Department Code (1-26): ", stdout);
fgets(code, sizeof(code), stdin);
fflush(stdin);
result = strtol(code, &p, 10);
if(code[0] != '\n' && (*p == '\n' || *p == '\0'))
{
if(result < 1)
{
fputs("! Error: Out of Range(1-26). Press Enter to continue", stdout);
fflush(stdin);
getchar();
clrscr();
main();
}
else
if(result > 26)
{
fputs("! Error: Out of Range(1-26). Press Enter to continue", stdout);
fflush(stdin);
getchar();
clrscr();
main();
}
else
{
clrscr();
getchar();
switch(result)
{
case 1:
fputs(station1, stdout);
break;
case 2:
fputs(station2, stdout);
break;
case 3:
fputs(station3, stdout);
break;
case 4:
fputs(station4, stdout);
break;
case 5:
fputs(station5, stdout);
break;
case 6:
fputs(station6, stdout);
break;
case 7:
fputs(station7, stdout);
break;
case 8:
fputs(station8, stdout);
break;
case 9:
fputs(station9, stdout);
break;
case 10:
fputs(station10, stdout);
break;
case 11:
fputs(station11, stdout);
break;
case 12:
fputs(station12, stdout);
break;
case 13:
fputs(station13, stdout);
break;
case 14:
fputs(station14, stdout);
break;
case 15:
fputs(station15, stdout);
break;
case 16:
fputs(station16, stdout);
break;
case 17:
fputs(station17, stdout);
break;
case 18:
fputs(station18, stdout);
break;
case 19:
fputs(station19, stdout);
break;
case 20:
fputs(station20, stdout);
break;
case 21:
fputs(station21, stdout);
break;
case 22:
fputs(station22, stdout);
break;
case 23:
fputs(station23, stdout);
break;
case 24:
fputs(station24, stdout);
break;
case 25:
fputs(station25, stdout);
break;
case 26:
fputs(station26, stdout);
break;
}
}
}
else
{
fputs("Invalid input. Please enter a number.", stdout);
fflush(stdin);
getchar();
clrscr();
main();
}
}