Im trying to write code so that it will open a file (worker and benefits) and then display them when asked at the start. I can do this but I would like to use functions. When I run my program it ends as soon as it starts. How do I set up functions so that they will run.
Ive tried renaming the functions to no sucess. Ive also found no help throught Youtube tutorials.
#include <stdio.h>
#include <stdlib.h>
int ans;
char Benefits[150];
char Worker[150];
int readfile();
int end();
int welcome();
int main()
{
int welcome()
{
puts("Hi, Welcome to whatever this is!!\n");
}
int readfile()
{
FILE*fpointer;
fpointer = fopen("Worker.txt","r");
char Worker[150];
while(!feof(fpointer))
{
fgets(Worker, 150, fpointer);
}
FILE*fpointer1;
fpointer = fopen("Benefits.txt","r");
char Benefits[150];
while(!feof(fpointer))
{
fgets(Benefits, 150, fpointer1);
}
fclose(fpointer);
}
int menu(char Benefits)
{
{
printf("1 - For option 1\n");
printf("2 - For option 2\n");
printf("3 - For option 3\n");
printf("4 - For option 4\n");
printf("5 - exit\n");
scanf("%1d", &ans);
}
{
if (ans==1)
puts(Benefits);
if (ans==2)
puts(Worker);
if (ans==3)
puts("This is option3");
if (ans==4)
puts("This is option4");
}
}
return 0;
}
I expect the output to print either of the files or exit. As of now It skips functions and ends the program.