hello,
im actually a diploma student. i have a C Programmming assignment that i've to pass up early next month (March,2002).
i'm having problem with this program:/* create.c */
/* create a friend file */
#include "mylib.c"
#include <stdio.h>
/* declare a simple record */
struct FriendRec {
int FriendID;
char Nick[10];
char Name[20];
char Address[25];
char Email[20];
char Tel[15];
int Month;
int Day;
};
/* declare global working var */
struct FriendRec Friend;
int iKount = 0;
char cKont = 'Y';
/* indicates FILE pointer */
FILE *fPtr;
main() {
/* open file for writing */
fPtr = fopen("friend.dat", "w");
if (fPtr == NULL) {
/* dispaly file creation error */
printf("\nUnable to open \"friend.dat\"! Aborts operation!");
} else {
do {
DispTitle();
GetFriendDetails();
StoreInFile();
GetKontinueYN();
} while (cKont=='Y' || cKont=='y');
CloseFile();
TempHalt();
}
}
DispTitle() {
/* display title */
ClrRow(3);
printf("\nThis program is to create a file with details of friend. ");
printf("\nUser have to key in friend information that will later");
printf("\nbe stored in a file named \"friend.dat\".");
ClrRow(1);
}
GetFriendDetails() {
/* assigns friendid*/
Friend.FriendID = 1001 + iKount;
printf("\nFriend Id : %d", Friend.FriendID);
iKount++;
/* get friend nick name */
printf("\nNick name: ");
gets(Friend.Nick);
/* get friend name */
printf("\nName: ");
gets(Friend.Name);
/* get friend address */
printf("\nAddress: ");
gets(Friend.Address);
/* get friend e-mail address */
printf("\nE-Mail: ");
gets(Friend.Email);
/* get friend telephone number */
printf("\nTel.Number : ");
gets(Friend.Tel);
/* get friend month of birth */
do {
printf("\nMonth Of Birth: ");
scanf("%d", &Friend.Month);
if (Friend.Month > 12 || Friend.Month < 0) {
printf("Invalid month!Between 0 - 12 pls!");
}
} while (Friend.Month > 12 || Friend.Month < 0);
/* get friend day of birth */
do {
printf("\nDay Of Birth: ");
scanf("%d", &Friend.Day);
if (Friend.Day > 31 || Friend.Day < 0) {
printf("Invalid day!Between 0 - 31 pls!");
}
} while (Friend.Day > 31 || Friend.Day < 0);
}
GetKontinueYN() {
/* get permission to Kontinue */
printf("Input next friend? [Y/N] : ");
cKont=getche();
ClrRow(1);
}
StoreInFile() {
fwrite(&Friend, sizeof(struct FriendRec), 1, fPtr);
}
CloseFile() {
/* close file */
fclose(fPtr);
printf("\nFile \"friend.dat\" is successfully appended!");
}
==============================================
The problem is, when u choose to input next friend, the cursor jumps from Friend ID to Name. I'm unable to input the nickname for the second person.
i've tried to change all possible codes but it doesnt work. this code is the same as the one that my lecturer gave me (on another lesson).
i really need someone to help me out. im really stressed now since the completion date is just around the corner.
Please Help!