Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void sortedInsert(struct listelement** list_ptr, struct listelement* newNode)
- {
- struct listelement* temp;
- while (((temp = *list_ptr) &&
- (temp->surveyDetails.ppsNo < newNode->surveyDetails.ppsNo))) {
- list_ptr = &temp->next;
- }
- newNode->next = temp;
- *list_ptr = newNode;
- }
- void addElement(struct listelement** list_ptr)
- {
- int inputPPS;
- struct listelement *list;
- struct listelement *newNode;
- list = *list_ptr;
- newNode = malloc(sizeof *newNode);
- if (list == NULL) {
- printf("\nWe will now take details from you for the survery...\n");
- }
- // keep asking for a PPS number, until we get a unique one
- while (1) {
- printf("\nPlease enter your PPS number (Number must be unique):");
- scanf("%d", &inputPPS);
- if (checkUnique(list, inputPPS)) {
- break;
- }
- printf("\nWe still value your feedback on this topic! If you believe you have entered your PPS incorrectly you can now try again!");
- }
- newNode->surveyDetails.ppsNo = inputPPS;
- printf("\nPlease enter your first name:");
- scanf("%*s", sizeof(newNode->surveyDetails.fName), newNode->surveyDetails.fName);
- printf("\nPlease enter your last name:");
- scanf("%*s", sizeof(newNode->surveyDetails.lName), newNode->surveyDetails.lName);
- //printf("\nEnter email address: ");
- //do email validation
- //scanf("%*s", sizeof(newNode->studentData.email), newNode->studentData.email);
- printf("\nEnter current address:");
- scanf("%*s", sizeof(newNode->surveyDetails.address), newNode->surveyDetails.address);
- printf("\nPlease enter your age:");
- scanf("%d", &newNode->surveyDetails.age);
- printf("\nPlease enter your yearly salary (as whole number):");
- scanf("%d", &newNode->surveyDetails.income);
- printf("\nHow many cigarrettes do you smoke a day? :");
- scanf("%d", &newNode->surveyDetails.ciggiesSmoked);
- printf("\nHow many units of alcohol do you drink in a day? :");
- scanf("%d", &newNode->surveyDetails.unitsTaken);
- printf("\nHow many time do you exercise every week? :");
- scanf("%d", &newNode->surveyDetails.timesExercised);
- sortedInsert(list_ptr, newNode);
- printf("\nSurvey stored successfully\n");
- }
- int checkUnique(struct listelement *list, int ppsNo)
- {
- struct listelement *temp;
- for (temp = list; temp; temp = temp->next) {
- if (temp->surveyDetails.ppsNo == ppsNo) {
- printf("\n There is a user in the survey system with this PPS Number.");
- return 0;
- }
- else if (temp->surveyDetails.ppsNo > ppsNo) {
- // the list is sorted, so if we find an element with a pps greater than
- // the one we're looking for, then we need look no further
- break;
- }
- }
- printf("\nPPS Number is unique. Continuing...\n We will now ask you for your survey details... ");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement