0

I have an assignment . I need to recive Data from a text file into an array of structures (in func,not in main). struct

>#define INPUT_FILE "c:\\in.txt"
#include<stdio.h>
#include<stdlib.h>
typedef struct
{
 int serial;
 char name[15];
 char dest[20];
 int taken;
 int date;
}flight;


void flights()
{
    FILE *fin;
   int taken,date,serial;
   char name[15],dest[20];
    fin=fopen(INPUT_FILE,"r");
    if (fin=NULL)
    {
        printf("Eror in opening file %s\n",INPUT_FILE);
        exit(1);
    }
    fscanf(fin,"%d",&serial);
    fgets(name,15,fin);
    fgets(dest,20,fin);
    fscanf(fin,"%d%d",&taken,&date);

}

I don't know how to import the date from the text file into the array of structures. Thanks all

Ben1
  • 21
  • 1
  • 2
  • Text files can not send their contents, thus, one can not receive data from text files – Shai Jun 07 '15 at 11:10
  • possible duplicate of [In C, how should I read a text file and print all strings](http://stackoverflow.com/questions/3463426/in-c-how-should-i-read-a-text-file-and-print-all-strings) – Shai Jun 07 '15 at 11:11
  • 2
    It will not solve the issue, but it's `if (fin==NULL)` – francis Jun 07 '15 at 11:27
  • You don't have an array of that structure in your code. That complicates things, as it depends (somewhat) on how you create it: statically? dynamically? fixed size, or automatically resizing to fit the number of entries? – Jongware Jun 07 '15 at 14:26

0 Answers0