Reading data from a text file

I'm at a lost here. I'm suppose to get the data from a text file and put those data into my struct, but I'm confuse on how to do that. I read on cplusplus on different functions I can use but I'm still confuse. From what I understand fgets and fscanf would be the most practical function for my case, but how do I make them read the code and separate the keyword from the definition?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Dict
{
 char key[];
 char def[];
}Dict;

int main(void)
{ 
 struct Dict DictEntries[5];
 FILE * dictionary = fopen("dictionary.txt","rt");
      if (dictionary == NULL)
      {
      printf("Dictionary file not found...\n") ;              
      while(getchar() != '\n');
      exit(-80);
      }
 }
 	fclose(dictionary); 
    fflush(stdin);
    getchar();
    return 0;
}


knife - an instrument for cutting
stove - a heat chamber or box for special purposes
cabinet - a piece of furniture with shelves, drawer used for storing items
cutting board - a board used as a firm surface for cutting food
pan - a broad, shallow container of metal used for cooking
Based on your input file, I would
read the line
copy line to key and def
Determine the location of the "-"
use string erase to get rid of unwanted chars.
The code shown so far is C rather than C++.
Is that deliberate, or would a C++ solution be acceptable?
Well I'm doing it in C right now and then converting it to C++ later.
Well ok. Do you still need help with this. If so would you prefer C or C++ responses?
I got this to work. I used fgets to read the file until it can't read anymore. Then I used strtok to split the string into two parts then assign the first part to keyword and the second part to definition.
Topic archived. No new replies allowed.