Hi i got a program to store words and number of spaces after each word.
Words would be in a word node.the code is:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/***********************************************************************************
wordNode stores the word,and the number of spaces after the word.
Also stores a link to the next word node.
***********************************************************************************/
typedef struct WordNode{
struct WordNode *nextWord;
char *word;
int numSpaces;
}wordNode;
/***********************************************************************************
makeWordNode() creates a newWord node.The parameters are string,the data to be assigned to the
wordNode.The other parameter is numSpaces,it assigns the number of spaces after a word
***********************************************************************************/
wordNode *makeWordNode(char* string,int numSpaces){
wordNode *newWordNode;
/*allocate memory for node*/
newWordNode=(wordNode*)malloc(sizeof(wordNode));
/*allocate memory for the word data*/
newWordNode->word=malloc(100*sizeof(char));
/*assign the string to the wordNode*/
strcpy(newWordNode->word,string);
/*assign numspaces to word node*/
newWordNode->numSpaces=numSpaces;
newWordNode->nextWord=NULL;
return newWordNode;
}
void freeNode(wordNode* node){
free(node->word);
free(node);
}
int main(void){
wordNode *a;
a=makeWordNode("first",1);
return 1;
}
i compiled it in unix.it work fine.when i use the bcheck memory leak checker,i get 2 errors.It seems the above code leaks memory at makeWordNode()
Can someone please help me find what's the error.I am clueless.do guide.
Thanking you,
Rahul SK