Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program in C. Use the skeleton code below. Fill the structure with all four values: views, user, times, titles #include #include #include #define LINE_LENGTH 100

Program in C. Use the skeleton code below. Fill the structure with all four values: views, user, times, titles

#include  #include  #include  #define LINE_LENGTH 100 struct clip *build_a_lst(); struct clip *append(); int find_length(); void print_lst(); void split_line(); struct clip { int views; char *user; char *id; char *title; struct clip *next; } *head; int main(int argc, char **argv) { int n; head = build_a_lst(*(argv+1)); n = find_length(head); printf("%d clips ",n); print_lst(head); /* prints the table */ return 0; } struct clip *build_a_lst(char *fn) { FILE *fp; struct clip *hp; char *fields[4]; char line[LINE_LENGTH]; int cnt=0; hp=NULL; // open fn // while no more lines // read a line // split the line into four substrings/int and store them in a struct // append - add the struct at the end of the list // return the head pointer holding the list return hp; } /* fields will have four values stored upon return */ void split_line(char **fields,char *line) { int i=0; char *token, *delim; delim = ", "; /* call strtok(line, delim); repeat until strtok returns NULL using strtok(NULL, delim); */ } /* set four values into a clip, insert a clip at the of the list */ struct clip *append(struct clip *hp,char **five) { struct clip *cp,*tp; /* malloc tp set views using atoi(*five) malloc for four strings. strcpy four strings to tp insert tp at the end of the list pointed by hp use cp to traverse the list */ return hp; } void print_a_lst(struct clip *cp) { /* use a while loop and the statement below to print the list printf("%d,%s,%s,%s,%s ",cp->views,cp->user,cp->id,cp->title,cp->time); */ } /* end */ 

Prepare a CSV file (comma sepearated value file) containing all the values. Each line of the CSV file will consist of views, user, id, titles. Use the same commands you used to create a table, except now that you have to put in "," (commas) in between the four values as delimiter. Note however that before you put in commas, you need to convert those pre-existing commas (some titles have commas unfortunately) to something else such as MY_COMMA or something of that sort. Later on you can revert MY_COMMA back to real commas when everything is said and done.

Use strtok() function to split a line into four fields with "," as the delimiter. As cautioned above, you need to convert commas to something else which can then be reverted back to commas after you have built a list. insert_at_end(char *s) will insert not just user but all the remaining values as well.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions