I am having a difficult time with my AddNode function. It takes in a head and data and makes a node, but when i run the program, it prints memory addresses or something.I just have no idea why its not working.
.
Main FunctionCODE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "LinkedFunctions.c"
int
main()
{
int numStu; // number of students enrolled in classes
int initStu;
int ID;
char classN[6];
int sect;
int cred;
char code[3];
int mod;
FILE *infilep, *outfilep;
infilep = fopen("Lab11InputData.txt", "r");
outfilep = fopen("Lab11OutputReport.txt", "w");
typedef struct class_node_s
{
char className[6];
int section;
int credits;
struct class_node_s * next;
}class_node_t;
typedef struct
{
int SID;
class_node_t * head;
}student_t;
fscanf(infilep, "%d", &numStu);
student_t students[numStu];
int i;
for(i = 0; i < numStu; i++)
{
fscanf(infilep, "%d", &students[i].SID);
students[i].head = ( class_node_t* )malloc( sizeof(class_node_t) );
}
fscanf(infilep, "%d", &initStu);
fscanf(infilep, "%d", &ID);
fscanf(infilep, "%s", classN);
fscanf(infilep, "%d", §);
fscanf(infilep, "%d", &cred);
for(i = 0; i < initStu; i++)
{
if(ID == (students[i].SID))
{
AddNode(students[i].head, ID, classN, sect, cred);
}
}
fprintf(outfilep, "%d : %s %d %d", students[2].SID, students[2].head->className, students[2].head->section, students[2].head->credits);
return(0);
}
"AddNode"CODE
void AddNode( struct class_node_t *head, int ID, char classN[], int sect, int cred)
{
typedef struct class_node_s
{
char className[6];
int section;
int credits;
struct class_node_s * next;
}class_node_t;
class_node_t *newNode;
newNode = (class_node_t*)malloc(sizeof(class_node_t));
strcpy(newNode->className, classN);
newNode->section = sect;
newNode->credits = cred;
newNode->next = 0;
head = newNode->className;
}
Also i don't quite understand how the node is being created if the code in AddNode is all local. i know it has to do with memory dynamically allocated to the heap