Question: How do I create a doubly linked list. For this main function. I want the title and genre in a doubly linked list and the
How do I create a doubly linked list. For this main function. I want the title and genre in a doubly linked list and the rating.
typedef struct movieInfo { char* title; char* genre; int* rating; struct movieInfo* prev; struct movieInfo* next; }movienfo;
int main() {
char title[30]; char genre[30]; int rating = 0; movieInfo* head=NULL; movienfo* tail= NULL;
while (1) { printf("DataStructure Assignment #1 "); printf("Please enter a title "); fgets(title, 30, stdin); if (strcmp(title, ". ") == 0) { break; }
printf("Please enter a genre "); fgets(genre, 30, stdin); if (strcmp(genre, ". ") == 0) { break; } eliminateEndOfLine(title); eliminateEndOfLine(genre);
//Getting number rating. It can only be between 1-5 printf("Please enter a rating between 1-5 "); rating = getNum(); if (rating < 1){ printf("The number you have entered in less then 1, "); } else if (rating > 5){ printf("The number you have entered is greater than 5 "); }
break; } printf("Output Here... ");
//heading for the output. char titleHeader[] = "Title"; char genreHeader[] = "Genre"; char ratingHeader[] = "Rating";
printf("%-30s %-30s %-30s ", titleHeader, genreHeader, ratingHeader);
return 0; }
#pragma warning(disable: 4996) int getNum(void) {/* the array is 121 bytes in size; we'll see in a later lecture how we can improve this code */ char record[121] = { 0 }; /* record stores the string */ int number = 0; /* NOTE to student: indent and brace this function consistent with your others */ /* use fgets() to get a string from the keyboard */ fgets(record, 121, stdin); /* extract the number from the string; sscanf() returns a number * corresponding with the number of items it found in the string */ if (sscanf(record, "%d", &number) != 1) { /* if the user did not enter a number recognizable by * the system, set number to -1 */ number = -1; } return number; }
/*==================================================================================================*/ /*FUNCTION :void eliminateEndOfLine */ /*PARAMETER :char *buffer */ /*RETURNS :void */ /*DESCRIPTIONS :*/ void eliminateEndOfLine(char* buffer) { char* target = strchr(buffer, ' '); if (target != NULL) { *target = '\0'; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
