Hey everyone! I'm new here, and new to the C language in general. I've been trying to read a .txt into a linked list in the attached code. I'm running into problems, specifically I'm getting errors on line 41 (curr->word=charTemp. I'm trying to set the word array equal to the charTemp array. I've tried strcpy with no luck . Any suggestions?
Code:
#include <stdio.h>#include <stdlib.h>
#include <string.h>
//Struct for linked list
typedef struct node
{
char word[25];
struct node *next;
} node;
//Start ##main##
int main()
{
char c;
char charTemp[25];
int i = 0;
//open files
FILE *oneFile;
oneFile=fopen("in1.txt", "r");
//start linked list
struct node *root; //First node (unchanging)
struct node *curr; //current node
root = (struct node*) malloc(sizeof (struct node));
root->next= 0;
curr=root;
do
{
c= fgetc(oneFile);
if(fgetc(oneFile)==" ")
{
//enter data into linked list
curr->next = malloc( sizeof(struct node));
curr->word=charTemp; ////#### PROBLEM CHILD
curr = curr->next;
}
else
{
charTemp[i] =c;
}
}
while(c != EOF);
}//End ##main##