Sams Teach Yourself C in 21 Days

(singke) #1
380 Week 2

95:
96: void get_data(void)
97: {
CH 11 98: int cont;
99:
100: for ( cont = YES; last_entry < MAX && cont == YES;last_entry++ )
101: {
102: printf(“\n\nEnter information for Person %d.”,last_entry+1 );
103:
104: printf(“\n\nEnter first name: “);
CH 14 105: gets(list[last_entry].fname);
106:
107: printf(“\nEnter last name: “);
CH 14 108: gets(list[last_entry].lname);
109:
110: printf(“\nEnter phone in 123-4567 format: “);
CH 14 111: gets(list[last_entry].phone);
112:
113: printf(“\nEnter Yearly Income (whole dollars): “);
CH 09 114: scanf(“%ld”, &list[last_entry].income);
115:
116: printf(“\nEnter Birthday:”);
117:
118: do
119: {
120: printf(“\n\tMonth (0 - 12): “);
CH 09 121: scanf(“%d”, &list[last_entry].month);
122: }while ( list[last_entry].month < 0 ||
123: list[last_entry].month > 12 );
124:
125: do
126: {
127: printf(“\n\tDay (0 - 31): “);
CH 09 128: scanf(“%d”, &list[last_entry].day);
129: }while ( list[last_entry].day < 0 ||
130: list[last_entry].day > 31 );
131:
132: do
133: {
134: printf(“\n\tYear (1800 - 1997): “);
CH 09 135: scanf(“%d”, &list[last_entry].year);
136: }while (list[last_entry].year != 0 &&
137: (list[last_entry].year < 1800 ||
138: list[last_entry].year > 1997 ));
139:
140: cont = continue_function();
141: }
142:
143: if( last_entry == MAX)
144: printf(“\n\nMaximum Number of Names has been entered!\n”);
145: }

LISTINGR2.1 continued

23 448201x-W2R 8/13/02 11:12 AM Page 380

Free download pdf