Question: Please explain how to code the following and make it match the outputs screenshotted. / / * * * / / * * * You

Please explain how to code the following and make it match the outputs screenshotted.
//***
//*** You may modify this file but don't submit it.
//***
#include
#include
#include
#include "hw10.h"
int main(int argc, char** argv)
{
if (argc !=3)
{
fprintf(stderr, "need two numbers
");
return EXIT_FAILURE;
}
int valn =(int) strtol(argv[1], NULL, 10);
int valk =(int) strtol(argv[2], NULL, 10);
if ((valn =1)||(valk =1))
{
return EXIT_FAILURE;
}
ListNode * head = NULL;
head = createList(valn);
eliminate(head, valk);
return EXIT_SUCCESS;
}
#include
#include
typedef struct ListNode {
int value;
struct ListNode* next;
} ListNode;
void printListNode(ListNode* head){
if (head == NULL) return;
ListNode* p = head;
printf("printListNode: ");
do {
printf("%d ", p->value);
p = p->next;
} while (p != head);
printf("
");
}
ListNode* createList(int valn){
if (valn =0) return NULL;
ListNode* head =(ListNode*)malloc(sizeof(ListNode));
head->value =0;
ListNode* current = head;
for (int i =1; i valn; i++){
ListNode* newNode =(ListNode*)malloc(sizeof(ListNode));
newNode->value = i;
current->next = newNode;
current = newNode;
}
current->next = head;
return head;
}
void eliminate(ListNode* head, int valk){
if (head == NULL || valk =0) return;
ListNode* current = head;
printListNode(head);
while (current->next != current){
for (int i =1; i valk -1; i++){
current = current->next;
}
ListNode* toDelete = current->next;
printf("printListNode: %d
", toDelete->value);
current->next = toDelete->next;
free(toDelete);
printListNode(current->next);
}
printf("printListNode: %d
", current->value);
}
//***
//*** You may modify this file but don't submit it.
//***
#ifndef HW10_H
#define HW10_H
#include
typedef struct node {
int value;
struct node* next;
} ListNode;
void printListNode(ListNode* head);
ListNode* createList(int valn);
void eliminate(ListNode* head, int valk);
ListNode* deleteNode(ListNode* head, ListNode* todelete);
#endif
Please explain how to code the following and make

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!