Untitled
unknown
plain_text
4 years ago
951 B
9
Indexable
#include <stdio.h>
#include <stdlib.h>
#include "assign.h"
static void load_list(struct list **lst, int argc, char *argv[])
{
int i = 0;
struct list *hdr = *lst;
for(int d = 1; d <= (argc - 1); d++)
{
i = (int)atoi(argv[d]);
if (hdr == NULL)
{
hdr = malloc(sizeof(struct list));
hdr->val = i;
}
else
{
struct list *curr = hdr;
while(curr->next != NULL)
curr = curr->next;
curr->next = malloc(sizeof(struct list));
curr->next->val = i;
}
}
}
int main(int argc, char *argv[])
{
if (argc < 2)
{
printf("Error: Enter a list of comma separated integers.\n");
exit(EXIT_FAILURE);
}
struct list *hdr = NULL;
load_list(&hdr, argc, argv);
if (hdr == NULL)
{
printf("Something went wrong .. exiting.");
exit(EXIT_FAILURE);
}
}
Editor is loading...