a C file that uses fopen for reading the file. code example

Example 1: how to take inputs and give outputs from a file in c

#include<stdio.h>

int main()
{
    FILE *fp;
    char ch;
    fp = fopen("one.txt", "w");
    printf("Enter data...");
    while( (ch = getchar()) != EOF) {
        putc(ch, fp);
    }
    fclose(fp);
    fp = fopen("one.txt", "r");
 
    while( (ch = getc(fp)! = EOF)
    printf("%c",ch);
    
    // closing the file pointer
    fclose(fp);
    
    return 0;
}

Example 2: c read file from command line

You can use as your main function:
int main(int argc, char **argv) 

So, if you entered to run your program:
C:\myprogram myfile.txt

argc will be 2
argv[0] will be myprogram
argv[1] will be myfile.txt

To read the file:
FILE *f = fopen(argv[1], "r");