The site wouldnt allow me to edit my post, so I could provide explanation.
So here it is with explanation.
Hey ...
I just typed this code, but I am getting pointer errors. This is a very basic program in pointer. Please help.
The pointers I am getting are:
* assignment from incompatible pointer type
* incompatible types in assignment
This is the code. I have highlighted the lines that have error. This is the main file.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "LinkedList.h"
#define MAX 10000 // maximum letters in a string
int main()
{
char string[WORD_LEN];
char fileName[WORD_LEN];
Node *List[MAX];//array of linked list
char token[WORD_LEN];// token to tokenize
int i = 0;
int result=0;
int bucket=0; // bucket for hashing
int key =0;
int linenum=0;
char input_file[MAX];
const char seperator[] = " !@#$%^&*()-<>-,./\{}?~`:;'\"";
Node *temp = NULL;
FILE *fp;
strcpy(fileName,"words.txt");
fp = fopen(fileName,"r");
if (fp == NULL)
{
printf("Cannot open file for reading\n");
return EXIT_FAILURE;
}
else
{
while(fgets(string, WORD_LEN, fp))
{
key = 0;
for (i=0;i<strlen(string);i++) // producing hash key
for the string
{
key += (int) string[i];
}
bucket = (int) key % MAX; //pucket number for the
string
temp = List[bucket];
if (List[bucket] == NULL)
temp=addhead(string,temp);// if that array
node is empty
else
List[bucket]=add(string,temp);
}
}
fclose(fp);
printf("The dictionary has been loaded into the Table array \n");
while (scanf("%s", input_file)!=EOF)
{
++linenum;
token = strtok(input_file,seperator);
key=0;
for(i=0;i<strlen(token);i++) //hashing
{
key += (int) token[i];
}
bucket = key % MAX;
i=0;
temp = List[bucket];
result = lookupDictionary(token, temp);
if (result == 0)
printf("Spelling error \n word: %s line: %d",token,linenum);
}
printf("\n Search complete \n");
printf("Program completed successfully\n");
return 0;
}
Node *newNode(char *string)
{
Node *newNode;
strcpy(newNode->string,strtok(string, " "));
newNode->next = NULL;
return(newNode);
}
Node *add(char *string, Node *temp)
{
Node *new = newNode(string);
temp->next = new;
return(new);
}
Node *addhead(char *string, Node *temp)
{
Node *new = newNode(string);
Node *head = NULL;
head = new;
return (new);
}
int lookupDictionary (char *word, Node *temp)
{
while (temp->string != word)
{
temp = temp->next;
}
if (temp->string == word)
return TRUE;
else
return FALSE;
}
This is the header file.
Code:
#ifndef _LINKEDLIST
#define _LINKEDLIST
#define TRUE 1
#define FALSE 0
typedef struct NODE Node;
#define WORD_LEN 15
struct NODE
{
char string[WORD_LEN];
struct Node *next;
};
Node *newNode(char *string);
Node *add(char *string, Node *temp);
Node *addhead(char *string, Node *temp);
int lookupDictionary (char word[0], Node *temp);
#endif
This program is supposed to input a list into the array of linked lists[I am trying to create a dynamic table].After that it takes a txt file and looks up the dictionary, which all words are presnt in the dictionary.
Please assist. I have just these 3 errors. Pointers drive me cuckoo..