Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create a directory called lab10 and move into that directory with cd lab10 Complete the lab10. c program shown below (you must write the two
Create a directory called lab10 and move into that directory with cd lab10 Complete the lab10. c program shown below (you must write the two functions whose signatures are shown in red). The program reads a file of integers (the filename is specified on the command line) and builds a linked list of the unique integer values and a count of how many times that integer value has been seen. addOrdered - adds the new integer to the existing list in numerical order (smallest to largest). If this is the first time the number has been added to the list, create a new node and set the count for that node to one (1). If the number already exists in the list, then increment the count for that number (do not create a second node for that number). printList - prints the ordered list of numbers (and their counts) #include #include typedef struct node {int value; int count; struct node *next;} Node; Node *addOrdered(Node *, int); void printList(Node *); int main(int argc, char *argv[]) {Node *head = NULL; if (argc != 2) {printf("Usage: ./a.out datafile "); exit(1);} FILE *fp = fopen(argv[1], "r"); if (! fp) {printf("File %s does not exist ", argv[1]); exit(1);} int num; fscanf(fp, "%d", &num); while (! feof(fp)) {head = addOrdered(head, num); fscanf(fp, "%d", &num);} printList(head); return 0;} Do not modify the code shown above, simply complete the two functions needed for its execution A sample execution with the data set data is shown below First, on your local machine, compress your lab10 directory into a single (compressed) file. Second, once you have a compressed file that contains your lab10 program, submit that file to Blackboard. #include #include typedef struct node {int value; int count; struct node *next;} Node; Node *addOrdered(Node *, int); void printList(Node *); int main(int argc, char *argv[]) {Node *head = NULL; if (argc != 2) {printf("Usage: ./a. out datafile "); exit(l);} FILE *fp = fopen(argv[1], "r"); if (! fp) {printf("File %s does not exist ", argv[1]); exit(1);} int num; fscanf(fp, "%d", &num); while (! feof(fp)) {head = addOrdered(head, num); fscanf(fp, "%d", & num);} printList(head); return 0;} Create a directory called lab10 and move into that directory with cd lab10 Complete the lab10. c program shown below (you must write the two functions whose signatures are shown in red). The program reads a file of integers (the filename is specified on the command line) and builds a linked list of the unique integer values and a count of how many times that integer value has been seen. addOrdered - adds the new integer to the existing list in numerical order (smallest to largest). If this is the first time the number has been added to the list, create a new node and set the count for that node to one (1). If the number already exists in the list, then increment the count for that number (do not create a second node for that number). printList - prints the ordered list of numbers (and their counts) #include #include typedef struct node {int value; int count; struct node *next;} Node; Node *addOrdered(Node *, int); void printList(Node *); int main(int argc, char *argv[]) {Node *head = NULL; if (argc != 2) {printf("Usage: ./a.out datafile "); exit(1);} FILE *fp = fopen(argv[1], "r"); if (! fp) {printf("File %s does not exist ", argv[1]); exit(1);} int num; fscanf(fp, "%d", &num); while (! feof(fp)) {head = addOrdered(head, num); fscanf(fp, "%d", &num);} printList(head); return 0;} Do not modify the code shown above, simply complete the two functions needed for its execution A sample execution with the data set data is shown below First, on your local machine, compress your lab10 directory into a single (compressed) file. Second, once you have a compressed file that contains your lab10 program, submit that file to Blackboard. #include #include typedef struct node {int value; int count; struct node *next;} Node; Node *addOrdered(Node *, int); void printList(Node *); int main(int argc, char *argv[]) {Node *head = NULL; if (argc != 2) {printf("Usage: ./a. out datafile "); exit(l);} FILE *fp = fopen(argv[1], "r"); if (! fp) {printf("File %s does not exist ", argv[1]); exit(1);} int num; fscanf(fp, "%d", &num); while (! feof(fp)) {head = addOrdered(head, num); fscanf(fp, "%d", & num);} printList(head); return 0;}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started