Linked list only grabbing last input of File contents - c

I'm trying to upload a list from a outside FILE into a linked list and have all the chars from the FILE be accessible on the list. I have this so far, but It only contains the last word from my input file list. I don't know what the problem is and I'm not sure where to go from here. Any help would be great! Thank you.
My .txt file that I'm uploading is just a bunch of nonsense words like:
Ted
Greg
Shoe
Money
Apple
When I run the program the list would only contain the would Apple.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXLEN 15
#define INPUT 1
#define OUTPUT 2
struct tree_node{
char string[MAXLEN+1];
struct tree_node *left_child, *right_child;
}*first = NULL;
int main(int argc, char *argv[])
{
char cell[MAXLEN];
int op;
FILE *pf;
FILE *out;
pf = fopen(("%s", argv[INPUT]), "r");
if(pf == NULL){
fprintf(stderr, "Error: File is Empty. \n");
return 0;
}else{
struct tree_node *temp;
struct tree_node *nn=(struct tree_node*)malloc(sizeof(struct tree_node));
while(!feof(pf)){
// fgets(&nn->string, MAXLEN, pf);
fscanf(pf, "%s", &nn->string); //I think this is where the problem is.
if(first != NULL){
temp = first;
while(temp -> right_child != NULL)
temp = temp -> right_child;
temp -> right_child = nn;
}else{
first = nn;
}
nn->right_child = NULL;
}
}
do{
printf("1.Display.\n2.Exit.\n");
printf("Selection?\n");
scanf("%d", &op);
switch(op)
{
case 1:display();
break;
}
}
while(op < 2 && op > 0);
}
int display()
{
struct tree_node *temp;
temp = first;
if(temp == NULL)
{
printf("EMPTY!\n");
return;
}
printf("Elements: \n");
while(temp != NULL){
printf("%s\n", temp -> string);
temp = temp -> right_child;
}
}

fscanf(pf, "%s", &nn->string); Here string is char array. so remove&.
You created only one node. This section above while().
struct tree_node *temp;
struct tree_node *nn=(struct tree_node*)malloc(sizeof(struct tree_node));
Need to create separate node for each string.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXLEN 15
#define INPUT 1
#define OUTPUT 2
#define EXIT 2
#define _S(x) #x
#define S(x) _S(x)
struct tree_node{
char string[MAXLEN+1];
struct tree_node *left_child, *right_child;
}*first = NULL;
void display(void);
void add_tree(char string[MAXLEN+1]);
int main(int argc, char *argv[]){
char cell[MAXLEN+1];
int op;
FILE *pf, *out;
if(NULL==(pf = fopen(argv[INPUT], "r"))){
fprintf(stderr, "Error: File can't open.\n");
return 1;
}
while(fscanf(pf, " %" S(MAXLEN) "[^\n]", cell)==1){
add_tree(cell);
}
fclose(pf);
do{
printf("1.Display.\n2.Exit.\n");
printf("Selection?\n");
scanf("%d", &op);
switch(op){
case 1:
display();
break;
}
} while(op != EXIT);
//release tree
return 0;
}
struct tree_node* new_node(char string[MAXLEN+1]){
struct tree_node *np = malloc(sizeof(*np));
if(np){
strcpy(np->string, string);
np->left_child = np->right_child = NULL;
}
return np;
}
void insert(struct tree_node **np, char string[MAXLEN+1]){
int cmp;
if(*np == NULL){
*np = new_node(string);
return;
}
if(0==(cmp=strcmp((*np)->string, string)))
return;
if(cmp > 0)
insert(&(*np)->left_child, string);
else
insert(&(*np)->right_child, string);
}
void add_tree(char string[MAXLEN+1]){
insert(&first, string);
}
void display_r(struct tree_node *np){
if(np){
display_r(np->left_child);
printf("%s\n", np->string);
display_r(np->right_child);
}
}
void display(void){
if(first == NULL){
printf("EMPTY!\n");
return;
}
printf("Elements: \n");
display_r(first);
}

Related

Segmentation fault error in Linked-List program

I'm facing the segmentation fault error in the following dynamic linked list implementation; GDB shows the issue is on the node = node->next line in the "l_print" function of the linked-list ("LIST_CL.H" file). Anyone can help? I even tried "drawing debug" on paper but still I'm not getting the issue here.
Note: I report the whole code for both the insert and the print, in case it's useful. Therefore LIST.C file include the "switch case 6" to insert the element ("l_add" function in "LIST_CL.H" file) and the "switch case 1" to print the list ("l_print" function in "LIST_CL.H" file)
Note: The issue only happen when the list has one or more items. There's no errors when the list is empty ("list_cl" struct has NULL for both head and tail nodes)
LIST.C:
#include <stdio.h>
#include <string.h> //for strcpy
#include "cl_list.h"
#include "list_cl.h"
#define STRING_SIZE 25
int main(){
list_cl class = L_EMPTYLIST_CL;
puts("Select command:");
puts("0. Exit.");
puts("1. Insert node.");
puts("6. Print all nodes in the linked list.");
int k = 0;
scanf("%d", &k);
while(k != 0){
switch(k){
case 1:
char cf[17] = "";
char first_name[STRING_SIZE] = "";
char last_name[STRING_SIZE] = "";
getchar();
puts("Insert name:");
fgets(first_name, sizeof(first_name), stdin);
puts("Insert surname:");
fgets(last_name, sizeof(last_name), stdin);
puts("Insert fiscal code:");
fgets(cf, sizeof(cf), stdin);
client cliente;
strcpy(cliente.cf, cf);
cliente.first_name = first_name;
cliente.last_name = last_name;
class = l_add_cl(class, cliente);
puts("Node inserted.");
break;
case 6:
l_print(class);
break;
default:
break;
}
scanf("%d", &k);
}
}
LIST_CL.H:
list_cl l_add_cl(list_cl l, client p){
l_node node;
node.id = 1;
node.person = p;
node.next = NULL;
if(l.head == NULL){
//List is empty
l.head = &node;
l.tail = &node;
} else {
l.tail -> next = &node;
l.tail = &node;
}
return l;
}
void l_print(list_cl l){
l_node *node = NULL;
node = l.head;
while(node != NULL){
//client *cliente = &node->person;
//printf("ID Elemento: %d | Name: %s Surname: %s Fiscal Code: %s", node->id, cliente->first_name, cliente->last_name, cliente->cf);
node = node->next; // SEGMENTATION FAULT ERROR HERE!
}
}
CL_LIST.H:
#include "client.h"
typedef struct _node {
unsigned int id;
client person;
struct _node *next;
} l_node;
typedef struct {
l_node *head;
l_node *tail;
} list_cl;
#define L_EMPTYLIST_CL {NULL,NULL}
CLIENT.H:
typedef struct {
char cf[17];
char *first_name;
char *last_name;
} client;
Fixed code:
LIST.C:
#include <stdio.h>
#include <string.h> //for strcpy
#include "cl_list.h"
#include "list_cl.h"
#define STRING_SIZE 25
int main(){
list_cl class = L_EMPTYLIST_CL;
puts("Seleziona un comando:");
puts("0. Exit.");
puts("1. Insert one node.");
puts("6. Print all nodes.");
int k = 0;
scanf("%d", &k);
while(k != 0){
switch(k){
case 1:
char cf[17] = "";
//char first_name[STRING_SIZE] = ""; THIS CAUSE DATA INCONSISTENCY
//char last_name[STRING_SIZE] = ""; THIS CAUSE DATA INCONSISTENCY
char *first_name = malloc(sizeof(char)*STRING_SIZE);
char *last_name = malloc(sizeof(char)*STRING_SIZE);
getchar();
puts("Insert name:");
//fgets(first_name, sizeof(first_name), stdin); ISSUE WITH SIZE OF FIRST_NAME
fgets(first_name, sizeof(char)*STRING_SIZE, stdin);
puts("Insert surname:");
//fgets(last_name, sizeof(last_name), stdin); ISSUE WITH SIZE OF LAST_NAME
fgets(last_name, sizeof(char)*STRING_SIZE, stdin);
puts("IInsert fiscal code:");
fgets(cf, sizeof(cf), stdin);
client *cliente = malloc(sizeof(client));
strcpy(cliente->cf, cf);
cliente->first_name = first_name;
cliente->last_name = last_name;
class = l_add_cl(class, *cliente);
puts("Element inserted.");
break;
case 6:
l_print(class);
break;
default:
break;
}
puts("Select command:");
scanf("%d", &k);
}
}
LIST_CL.H
list_cl l_add_cl(list_cl l, client p){
l_node *node = malloc(sizeof(struct _node));
node->id = 1;
node->person = p;
node->next = NULL;
if(l.head == NULL){
//Empty list
l.head = node;
l.tail = node;
} else {
l.tail -> next = node;
l.tail = node;
l.tail -> next = NULL;
}
return l;
}
void l_print(list_cl l){
l_node *node = NULL;
node = l.head;
while(node != NULL){
client *cliente = &node->person;
printf("ID Element: %d | Name: %s Surname: %s Fiscal code: %s", node->id, cliente->first_name, cliente->last_name, cliente->cf);
node = node->next;
}
}
CL_LIST.H
#include "client.h"
typedef struct _node {
unsigned int id;
client person;
struct _node *next;
} l_node;
typedef struct {
l_node *head;
l_node *tail;
} list_cl;
#define L_EMPTYLIST_CL {NULL,NULL}
CLIENT.H
typedef struct {
char cf[17];
char *first_name;
char *last_name;
} client;

Linked list shows segmentation fault error

I'm pretty new to C and pointers.
Following codes are for implementing a linked list in which each node contains a data of record.
However, when I compile and run this program, it shows an error "segmentation fault", and I guess the following part from my code makes an error.
head->next = NULL in functions in list.c
I doubt the segmentation fault error happens due to dereferencing a null pointer but have no idea what's wrong with my code.
list.h
#ifndef LIST_H
#define LIST_H
#include <stddef.h>
#include "record.h"
typedef struct node node;
struct node {
record data;
node *next;
};
typedef node *record_list; /* a record list is represented by its "head"
pointer */
void list_init(record_list *plist);
int list_insert(record_list *plist, const record *prec);
void list_clear(record_list *plist);
void list_print(const record_list *plist);
#endif
io.h
#ifndef IO_H
#define IO_H
#include "record.h"
void print_record(const record *p);
int read_record(record *p);
/* reads a string from stdin */
int get_word(const char prompt[], char word[]);
/* reads an int from stdin */
int get_int(const char prompt[], int *p);
#endif
record.h
#ifndef RECORD_H
#define RECORD_H
#define IDSIZE 10
#define NAMESIZE 20
typedef struct {
char last[NAMESIZE];
char first[NAMESIZE];
} name;
typedef struct {
char id[IDSIZE];
name name;
int score;
} record;
#endif
list.c
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "record.h"
#include "list.h"
#include "io.h"
/* initializes a record list (specified via plist) to an empty list */
void list_init(record_list *plist) {
node *head;
head = *plist;
head = NULL;
head->next = NULL;
printf("%s", "segmentation???\n");
}
/*
* inserts a record (specified via prec) into a record list
*/
int list_insert(record_list *plist, const record *prec) {
node *current, *temp;
printf("%s", "list insert\n");
current = *plist;
while (current->next != NULL) {
current = current->next;
}
temp = (node *)malloc(sizeof(node));
if (temp == NULL) {
fprintf(stderr, "memory allocate failed");
return 0;
}
current->next = temp;
current->next->data = *prec;
current->next->next = NULL;
printf("%s", "list insert done\n");
return 1;
}
/*
* deallocates all dynamic memory associated with a record list (specified
* via plist) & resets the record list to an empty list
*/
void list_clear(record_list *plist) {
printf("%s", "list clear\n");
free((*plist)->next);
plist = NULL;
(*plist)->next = NULL;
}
/* prints all records in a record list (specified via plist) */
void list_print(const record_list *plist) {
node *current;
current = *plist;
printf("%s", "list print\n");
while (current->next != NULL) {
print_record(&(current->data));
current = current->next;
}
}
io.c
#include <stdio.h>
#include <string.h>
#include "record.h"
#include "io.h"
#define LINESIZE 1024
/*
* prints a record (specified via p);
*/
void print_record(const record *p) {
printf("%d %s %s %s\n", p->score, p->name.last, p->name.first, p->id);
}
/*
* reads a record from stadard input & stores it via p;
*/
int read_record(record *p) {
return (
get_word("Enter id: ", p->id)
&& get_word("Enter last name: ", p->name.last)
&& get_word("Enter first name: ", p->name.first)
&& get_int("Enter score: ", &(p->score))
);
}
/* reads a string from stdin */
int get_word(const char prompt[], char word[]){
char line[LINESIZE];
char temp[LINESIZE];
while (1) {
printf("%s", prompt);
if(!fgets(line, LINESIZE, stdin)){
clearerr(stdin);
return 0;
}
if (sscanf(line, "%s", temp) == 1){
strcpy(word, temp);
return 1;
}
}
}
/* reads an int from stdin */
int get_int(const char prompt[], int *p) {
char line[LINESIZE];
while (1) {
printf("%s", prompt);
if (!fgets(line, LINESIZE, stdin)) {
clearerr(stdin);
return 0;
}
if (sscanf(line, "%d", p) == 1) {
return 1;
} else {
printf("%s", "Error: The input is not given in integer.\n");
}
}
}
main.c
#include <stdio.h>
#include "record.h"
#include "list.h"
#include "io.h"
int main(void) {
record_list list;
record r;
printf("address of list: %ld\n", &list);
printf("address of list: %ld\n", &(list->next));
list_init(&list);
while (read_record(&r)) {
printf("%s\n", "read success");
if (!list_insert(&list, &r))
break;
}
list_print(&list);
return 0;
}
If your goal is to create an empty list and plist is the pointer to the head of the list you have to set the variable pointed by plist to NULL with *plist = NULL; , you can get rid of the code is causing the segmentation fault
Ok I think I find the next error:
current = *plist;
while (current->next != NULL) {
current = current->next;
}
Will cause errors because the first time you call list_insert you have *plist equals to NULL because the list is empty and so current->next != NULL will cause the error (current is also equals to NULL)
I suggest the following:
printf("%s", "list insert\n");
if (*plist == NULL) {
temp = (node * )malloc(sizeof(node));
if (temp == NULL) {
fprintf(stderr, "memory allocate failed");
return 0;
}
plist = temp;
(*plist) ->data = *prec;
(*plist) ->next = NULL;
return 1;
}
current = *plist;
while (current->next != NULL) {
current = current->next;
}
And the rest of the code as it was, I added an if for the case *pilist is equals to NULL, in that case temp is going to point at the first element and has to be assigned to plist

Reading stdin strings and adding it to BST in C

I'm attempting to insert stdin strings into a binary search tree, and then output the inorder and postorder traversals. My problem is it seems like older nodes are being overwritten by the most recent, but I can't figure out why. So my inorder/postorder methods return the last inserted string how many times there are nodes in the tree.
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
#include <ctype.h>
#include "bstsort.h"
/* Case Sensitive String Comparison */
int strcmpCase(char* string1, char* string2) {
while(*string1 && (*string1==*string2)) {
string1++;
string2++;
}
return *string1 - *string2;
}
/* Case Insensitive String Comparison */
int strcmpNoCase(char* string1, char* string2) {
int i;
char a[100];
char b[100];
strcpy(a, string1);
strcpy(b, string2);
for (i = 0; a[i]; ++i) {
a[i] = tolower(a[i]);
}
for (i = 0; b[i]; ++i) {
b[i] = tolower(b[i]);
}
return strcmpCase(a, b);
}
/* Inserts a Node into the Binary Search Tree */
void insert(struct Node **node, char *keyStr, int cflag) {
// Creates new node
if (*node == NULL) {
*node = (struct Node*) malloc (100);
strcpy((*node)->key, keyStr);
(*node)->left = NULL;
(*node)->right = NULL;
(*node)->count = 1;
return;
}
// Compares Strings
int compareResult;
if (cflag == 1){
// Case sensitive
compareResult = strcmpCase(keyStr, (*node)->key);
} else {
// Case insensitive
compareResult = strcmpNoCase(keyStr, (*node)->key);
}
// Moves down branches of BST to insert node in correct order
if (compareResult < 0) {
insert(&((*node)->left), keyStr, cflag);
} else if (compareResult > 0) {
insert(&((*node)->right), keyStr, cflag);
}
(*node)->count++;
return;
}
/* Outputs in-order traversal or BST */
void inorder(Node* root) {
if (root != NULL) { // if current node is not null
inorder(root->left); // travel down left child, recursively
printf("%s", root->key); // prints key of current node, the root
inorder(root->right); // travel down right child after root printed, recursively
}
}
void postorder(Node* root) {
printf("Postorder: \n");
if (root != NULL) { // if current node is not null
postorder(root->left); // travel down left child, recursively
postorder(root->right); // travel down right child, recursively
printf("%s", root->key); // prints key of current node, the root
}
}
int main(int argc, char **argv) {
extern char *optarg;
extern int optind;
int c, err = 0, i = 0, numRead, isfirst = 1;
int cflag = 0, oflag = 0;
char *inName = NULL; // Input filename
char *outName = NULL; // Output filename
static char usage[] = "Usage: bstsort [-c] [-o output_file_name] [input_file_name]\n";
FILE* inFile = NULL;
FILE* outFile = NULL;
char *line;
char tmp[100] = "";
struct Node *root = NULL;
while ((c = getopt(argc, argv, "co:")) != -1)
switch (c) {
case 'c':
cflag = 1;
break;
case 'o':
oflag = 1;
outName = optarg;
break;
case '?':
err = 1;
break;
}
if (err) {
fprintf(stderr, usage, argv[0]);
exit(1);
}
/* see what we have */
printf("cflag: %d\n", cflag);
printf("oflag: %d\n", oflag);
printf("Output Filename: \"%s\"\n", outName);
/* these are the arguments after the command-line options */
if (optind < argc) {
for (; optind < argc; optind++) {
inName = argv[optind];
printf("Input Filename: \"%s\"\n", inName);
}
} else {
printf("No input filename provided.\n");
}
/* Reads stdin one line at a time when input filename not provided*/
line = (char*) malloc (100);
if (inName == NULL) {
printf("\nEnter one line at a time:\n");
fflush(stdout);
fgets(line, 100, stdin);
insert(&root, line, cflag);
while (strcmp(line, "\n") != 0) {
fflush(stdout);
fgets(line, 100, stdin);
if (strcmp(line, "\n") != 0) {
insert(&root, line, cflag);
}
}
}
inorder(root);
postorder(root)
free(line);
free(root);
fclose(inFile);
exit(0);
}
Here's my Node struct
#ifndef BSTSORT_H
#define BSTSORT_H
/* Binary Search Tree Node Struct */
typedef struct Node {
char *key;
int count;
struct Node *left;
struct Node *right;
} Node;
void insert(Node **node, char *keyStr, int cflag);
void inorder(Node* root);
void postorder(Node* root);
void display_tree(Node* nd);
#endif
Any tips would be great.

Writing a program to take data from file then store in BST

I'm writing a program to take data to store in a BST.
My problem is I don't know what's wrong with my MakeNewNode and Insert function.
I tried both of them the printed data didn't come out as expected. Please help
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct example
{
char MSKH[13];
char ten[30];
char tong[12];
int thucpham;
int dientu;
int maymac;
}KeyType;
typedef struct node
{
KeyType key;
struct node* left;
struct node* right;
}NodeType;
typedef NodeType* TreeType;
NodeType* MakeNewNode(KeyType a)
{
NodeType* NewNode;
NewNode = (NodeType *)malloc(sizeof(NodeType));
if (NewNode != NULL)
{
strcpy(a.MSKH,((NewNode)->key).MSKH);
strcpy(a.ten,((NewNode)->key).ten);
strcpy(a.tong,((NewNode)->key).tong);
((NewNode)->key).thucpham = a.thucpham;
((NewNode)->key).dientu = a.dientu;
((NewNode)->key).maymac = a.maymac;
/*strcpy(a.thucpham,(NewNode->key).thucpham);
strcpy(a.dientu,(NewNode->key).dientu);
strcpy(a.maymac,(NewNode->key).maymac);*/
(NewNode)->left = NULL;
(NewNode)->right= NULL;
}
return NewNode;
}
void Insert(KeyType a, TreeType *Root)
{
if(*Root == NULL)
{
*Root = (NodeType *)malloc(sizeof(NodeType));
strcpy(a.MSKH,((*Root)->key).MSKH);
strcpy(a.ten,((*Root)->key).ten);
strcpy(a.tong,((*Root)->key).tong);
((*Root)->key).thucpham = a.thucpham;
((*Root)->key).dientu = a.dientu;
((*Root)->key).maymac = a.maymac;
/*strcpy(a.thucpham,(Root->key).thucpham);
strcpy(a.dientu,(Root->key).dientu);
strcpy(a.maymac,(Root->key).maymac);*/
(*Root)->left = NULL;
(*Root)->right= NULL;
}
else if (strcasecmp(a.MSKH,((*Root)->key).MSKH) < 0) Insert(a,&(*Root)->left);
else if (strcasecmp(a.MSKH,((*Root)->key).MSKH) > 0) Insert(a,&(*Root)->right);
}
void Traverse(TreeType Root){
if (Root != NULL)
{
Traverse(Root->left);
printf("%s %s %s %d %d %d\n",(Root->key).MSKH,(Root->key).ten,(Root->key).tong,(Root->key).thucpham,(Root->key).dientu,(Root->key).maymac);
Traverse(Root->right);
}
}
int main(){
FILE* fin, *fout;
fin = fopen("F:\\text.txt","r");
char line[256];
TreeType root=NULL;
KeyType hoadon;
fscanf(fin,"%13s %30s %12s %d %d %d",&hoadon.MSKH,&hoadon.ten,&hoadon.tong,&hoadon.thucpham,&hoadon.dientu,&hoadon.maymac);
printf("%s %s %s %d %d %d\n",hoadon.MSKH,hoadon.ten,hoadon.tong,hoadon.thucpham,hoadon.dientu,hoadon.maymac);
root = MakeNewNode(hoadon);
printf("%s",(root->key).MSKH);
fclose(fin);
}
Example of data from txt file: CLA012032A1 NguyenNam 12000000 1 2 3

i got some issues reading words from a .txt file in C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define WORD_LENGHT 30
typedef struct numnode
{
char* dataPtr;
struct numnode* next;
} NUMNODE;
typedef struct num
{
NUMNODE* head;
} NUM;
//////
//////
//////
int main()
{
char *wp;
char word[80];
int total=0;
FILE *test= fopen("book.txt", "r");
while (fscanf (test, "%s",word) == 1)
{
//printf("%s\n",word); //counting how many words in a book.txt
total++;
}
if (total==0)
{
printf("File not found\n"); //if no word, then return
return;
}
NUM* dic;
dic=(NUM*)malloc(sizeof(NUM)*total);
NUMNODE* temp;
temp=dic->head;
FILE*file = fopen("book.txt", "r");
while(!feof(file))
{
wp=malloc(100);
printf("test1\n");
fscanf(file,"%s",wp);
strcpy(temp->dataPtr,wp); //strcpy is the error part
printf("test2\n");
temp=temp->next;
}
return;
}
this c code read word by word from book.txt and put them to linked
list. i got some issues with !feof(file) part.Couldnt figure out what
to do.i think strcpy in this loop is the reason of this issue.im
waiting for your helps :3
Error is because the struct member dataPtr is a pointer, not an array. So the strcpy call
strcpy(temp->dataPtr,wp);
is wrong because it accesses illegal memory invoking undefined behaviour. What you need is
typedef struct numnode
{
char dataPtr[100]; // dataPtr changed to an array type
struct numnode* next;
} NUMNODE;
Please note that dataPtr must be at least the size of the buffer pointed to by wp.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define WORD_LENGHT 30
typedef struct numnode {
char* dataPtr;
struct numnode* next;
} NUMNODE;
typedef struct num {
NUMNODE* head;
} NUM;
int main(){
NUM dic = { NULL };
char word[WORD_LENGHT];
int total=0;//num of word
FILE *file= fopen("book.txt", "r");
NUMNODE *curr = NULL, *temp;
while (fscanf(file, "%29s", word) == 1) {
temp = malloc(sizeof(*temp));
temp->dataPtr = malloc(strlen(word) + 1);
temp->next = NULL;,
strcpy(temp->dataPtr, word);
if(curr){
curr = curr->next = temp;
} else {
dic.head = curr = temp;
}
++total;
}
if (total==0){
printf("File does not has word\n");
return;
}
//test print
printf("%d\n", total);
if(total>1){
printf("%s\n", dic.head->dataPtr);
printf("%s\n", dic.head->next->dataPtr);
}
//do something
return;
}
,

Resources