I want to print the content of a txt file (first parameter), but the function to do so is in a different file. I have the following main file:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "fileoperation.h"
int main(int argc, char **argv)
{
read(argv[1]);
return 0;
}
and then in the fileoperation.c file I have:
#include "fileoperation.h"
void read(char* file)
{
FILE *fptr;
char c;
fptr = fopen(file, "r");
if (fptr == NULL)
{
printf("Cannot open file \n");
exit(0);
}
c = fgetc(fptr);
while (c != EOF)
{
printf ("%c", c);
c = fgetc(fptr);
}
fclose(fptr);
}
If I type the code from the function in the main function, it works. I don't understand why is not working
The header file of fileoperation.c is
#ifndef FILEOPERATION_H
#define FILEOPERATION_H
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void read(char* file);
#endif