Hello everyone,
I am sort of new in C programming and since I programmed mostly in C++, I may have some mix up on my program which is giving me some errors. I have written a small code , in modular fashion i.e. I have split the .h, definition.c , and main.c files.
The program currently has only one function and all that does is read from a text file. My problem is when I compile each file separately I get the error: 'Undefined reference to ReadFromfFile()" (Note: ReadFromFile is a function defined in definition.c and I get this error when I compile the main.c file)
And when I compile the definition.c file I get the error 'Undefined reference to main'.
And when I compile all my files together as such: gcc DeliveryServices.h DeliveryServices.c main.c -o Servrices: I get the error 'Segmentation fault(core dumped)'.
Please someone point me out what am I doing wrong and how can I fix it.
Thank you.
//Header File
#ifndef DeliveryServices_H
#define DeliveryServices_H
#include <stdio.h>
#include <string.h>
struct DeliveryServices{
char* ItemType;
char* PickUpAdd;
char* DropOffAdd;
};
typedef struct DeliveryServices ServiceSlip;
#endif
//Definition File
#include "DeliveryServices.h"
#include <stdio.h>
#include <string.h>
char ReadFromFile()
{
FILE *ReadFrom;
char lineRead;
printf("Hello");
ReadFrom = fopen("datafile.txt","r");
while(fgets(lineRead,120,ReadFrom))
{
printf("%s",lineRead);
}
return 0;
}
//Main.c
#include "DeliveryServices.h"
#include <stdio.h>
#include <string.h>
int main()
{
FILE *ReadFile;
char lineRead;
ServiceSlip PackageSlips;
ReadFromFile();
//PackageSlips.ItemType ="Package";
//printf("%s",PackageSlips.ItemType);
return 0;
}