Our teacher requires us to use turbo c on our assignments. The program is working fine on other compiler applications but it doesn't with turbo c. Here is the code:
#include<stdio.h>
struct Name
{
char last[100];
char first[100];
};
struct Address
{
char province[100];
int zipCode;
};
struct PBEntry
{
struct Name name;
struct Address address;
int age;
long int mobile;
}pb[10];
void showAll(struct PBEntry *p, int SIZE);
int main()
{
int choice = 1, SIZE=0, c=0, j;
clrscr();
printf("Welcome to Phonebook Application\n");
while(choice != 4 )
{
struct PBEntry *p;
struct PBEntry edit[10];
printMenu();
scanf("%d", &choice);
switch(choice)
{
case 1:
printf("Enter Entry %d\n", SIZE);
printf("Enter full name: ");
gets(pb[SIZE].name.first);
gets(pb[SIZE].name.last);
printf("Enter province: ");
gets(pb[SIZE].address.province);
printf("Enter ZIP code: ");
scanf("%d", &pb[SIZE].address.zipCode);
printf("Enter age: ");
scanf("%d", &pb[SIZE].age);
printf("Enter mobile number: ");
scanf("%ld", &pb[SIZE].mobile);
SIZE++;
break;
case 2:
printf("What entry number to edit?: ");
scanf("%d", &j);
printf("Change Entry %d\n", j);
printf("Change full name: ");
gets(pb[j].name.first);
gets(pb[j].name.last);
printf("Change province: ");
gets(pb[j].address.province);
printf("Change ZIP code: ");
scanf("%d", &pb[j].address.zipCode);
printf("Change age: ");
scanf("%d", &pb[j].age);
printf("Change mobile number: ");
scanf("%ld", &pb[j].mobile);
c++;
case 3:
showAll(pb, SIZE);
break;
case 4:
exit(0);
}
}
getch();
}
void showAll(struct PBEntry *p, int SIZE)
{
struct PBEntry edit[10];
int i=0, c=0;
while(i != SIZE)
{
if(c>0)
{
p = &edit;
printf("Entry %d\n", i);
printf("Name: %s %s\n", p[i].name.first, p[i].name.last);
printf("Province: %s\n", p[i].address.province);
printf("ZIP code: %d\n", p[i].address.zipCode);
printf("Age: %d\n", p[i].age);
printf("Phone number: %ld\n", p[i].mobile);
printf("\n");
}
else
{
p = &pb;
{
printf("Entry %d\n", i);
printf("Name: %s %s\n", p[i].name.first, p[i].name.last);
printf("Province: %s\n", p[i].address.province);
printf("ZIP code: %d\n", p[i].address.zipCode);
printf("Age: %d\n", p[i].age);
printf("Phone number: %ld\n", p[i].mobile);
printf("\n");
}
}
i++;
}
}
int printMenu()
{
printf("\n1. Add Entry\n");
printf("2.Edit Entry\n");
printf("3 Show All\n");
printf("4 Exit\n");
}
Our phone number here has 11 digits, or 12 at maximum. But long int, and even unsigned lont in, does not work on turbo c. I don't know where I went wrong.