Commit e1862e8d authored by kjc015's avatar kjc015
Browse files

Prelab Complete

parent c91e5e0c
CFLAGS=-Wall -Werror
all: strnode_test
strnode_test: strnode.o strnode_test.o strnode.h
rm -f strnode_test *.o
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "strnode.h"
struct strnode *strnode_create(char* s, int length){
struct strnode node;
struct strnode* address = malloc(sizeof(node));
strcpy((*address).str, s);
(*address).length = length;
(*address).next = 0;
return address;
#ifndef STRNODE_H_
#define STRNODE_H_
struct strnode{
char str[101];
int length;
struct strnode *next;
struct strnode *strnode_create(char *s, int length);
#include <stdio.h>
#include "strnode.h"
// global variables (data segment)
struct strnode *n1, *n2, *n3, *p;
//------------ MY MAIN FUNCTION --------------------
int main(int argc, char *argv[]) {
// create strnodes
n1 = strnode_create("hello", 5);
n2 = strnode_create("there", 5);
n3 = strnode_create("prof", 4);
printf("strnode_test running...\n");
// manually "link" the nodes together.
n1->next = n2;
n2->next = n3;
n3->next = NULL;
// p points to node n1 initially
p = n1;
while (p != NULL) {
// Complete this line to print the current node's string and
// the stored length (do not use strlen!)
printf("str: %s - length: %d\n", (*p).str, (*p).length);
// TODO: add code to move p to point to next node
// until you add this line, this program will have an infinite loop.
p = (*p).next;
return 0;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment