Sweet. Thanks for your help and patience everyone! I finally have it working with the following code:
Code:
void input () /* gets an entry from the user */
{
contact entry = {'\0','\0','\0','\0','\0','\0','\0','\0'}; /* initializes the structure */
char prompt1[26] = "Please enter a new name.";
char prompt2[25] = "Enter a street address.";
char prompt3[14] = "Enter a city.";
char prompt4[18] = "Enter a province.";
char prompt5[19] = "Enter a post code.";
char prompt6[17] = "Enter a country.";
char prompt7[23] = "Enter a date of birth.";
char prompt8[22] = "Enter a phone number.";
char prompt9[24] = "Enter an email address.";
get_input (prompt1, entry.name, sizeof(entry.name));
get_input (prompt2, entry.add.street, sizeof(entry.add.street));
get_input (prompt3, entry.add.city, sizeof(entry.add.city));
get_input (prompt4, entry.add.state, sizeof(entry.add.state));
get_input (prompt5, entry.add.post, sizeof(entry.add.post));
get_input (prompt6, entry.add.country, sizeof(entry.add.country));
get_input (prompt7, entry.birth, sizeof(entry.birth));
get_input (prompt8, entry.phone, sizeof(entry.phone));
get_input (prompt9, entry.email, sizeof(entry.email));
save_entry (entry);
}
int get_input (char prompt[], char string[], int size)
{
char *fgets_ptr;
char junk = 0;
int length;
do{
printf ("\n%s\n>", prompt);
fgets(string, size, stdin);
if (fgets_ptr==NULL) return -1 ;
if ( strchr(string, '\n') == NULL ){ /* if overflow */
printf ("\nYour entry is too long, please try again.\a");
while((junk = getchar()) != '\n' && junk != EOF);
string[0] = '\0';
}
} while (string[0] == '\0' || string[0] == '\n');
length = strlen(string);
if (string[length - 1] == '\n'){
string[length - 1] = '\0';} /* replace \n */
}