I am a newbie to C, i am trying to do similar coding to this.
but for some reason gets
, asking for name for new record keep getting skipped.
/* Define libraries to be included */
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <ctype.h>
/* Define Structures*/
typedef struct contact {
int number; /*unique account number*/
char name[20]; /*contains name*/
char phone[15]; /*contains phone number*/
char email[20]; /*contains email address*/
struct contact *next; /*next is used to navigate through structures.*/
int count; /*count is used to input comments into array*/
} Contact;
void addNewContact(void) /* add new contact function*/
{
newRecord = (struct contact*)malloc(sizeof(struct contact));
if (firstRecord == NULL) {
firstRecord = currentRecord = newRecord;
}
else {
currentRecord = firstRecord;
while (currentRecord->next != NULL)currentRecord = currentRecord->next;
currentRecord->next = newRecord;
currentRecord = newRecord;
}
currentRecordNumber++;
printf("%27s: %5i\n", "contact number", currentRecordNumber);
currentRecord->number = currentRecordNumber;
fflush(stdin);
printf("Enter contact name");
gets(currentRecord->name);/*this got skipped(no input asked)*/
fflush(stdin);
printf("Enter contact Phone number");
gets(currentRecord->phone);
fflush(stdin);
printf("Enter contact email");
gets(currentRecord->email);
fflush(stdin);
printf("contact added!");
currentRecord->count = 0;
currentRecord->next = NULL;
}