I need to initialize a linked list using ints given from the main.c.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char ** argv)
{
int b = 128;
int M = b * 11; // so we have space for 11 items
char buf [1024];
memset (buf, 1, 1024); // set each byte to 1
char * msg = "a sample message";
Init (M,b); // initialize
I know what I have isn't correct, but it's the best I could come up with.
#include <stdio.h>
#include "linked_list.h"
struct node
{
int value;
struct node *next;
};
struct node* head;
struct node* tail;
void Init (int M, int b)
{
head = (struct node *) malloc(sizeof *head);
tail = (struct node *) malloc(sizeof *tail);
head->next = tail;
tail->next = tail;
}
I just cannot see how to initialize the linked list using the ints. Thank you.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…