I have to affect a character from a structure to another and I have a mistake but I don't get where is it coming from. Here is the .txt file :
stabilimetre stabilimetre Nom:Mas SG
Here is the first structure :
typedef struct s_node
{
char letter; //This one
struct s_node* f_letters[26];
word* flechies;
}t_node;
typedef struct s_tree
{
t_node* root;
}t_tree;
And here is the second :
typedef struct
{
char content[100];//This one
char base_word[100];
int nature;
int genre;
int nombre;
int temps;
int personne;
}word;
In this case I want to put one of the character from content to letter from the other structure. So this is how I procede :
int main () {
FILE *fp;
char str[5000];
char type[100];
t_tree Letter;
t_node* temp;
Letter.root=NULL;
t_node first;
fp = fopen("dico_reducted.txt" , "r");
if(fp == NULL) {
perror("Error opening file");
return(-1);
}
while (fgets (str, sizeof(str), fp)!=NULL) {
word A;
sscanf(str,"%s\t%s\t%s:%s",&A.content, &A.base_word, &type);
Letter.root = &first;
first.letter = 'N';
first.f_letters[0] = temp;
temp->letter = A.content[0]; //This is the line where the error is coming from
}
fclose(fp); // Close the file
return 0;
}
This other line take a text from a .txt file and the first word is putted inside A.content. I'm actually trying to create a tree with the letter of this word.
I've tried to find out if the type are different between A.content[0] and temp.letter but it seems to be the same.
Actually the output I have now is nothing but an error. The final output would be a tree with letter in every node.
CodePudding user response:
temp is not initialized. It not pointed any real object.