I am trying to make a compiler for my project using C but I have a problem on how to store the contents of the text file into an array or something similar so that my program can compiler or analyze my txt (code) file. Here is what I have so far in my main excluding the other functions (to make the code shorter here):
#include <stdio.h>
#include <string.h>
char *prog; /* holds expression to be analyzed */
const char file_name[] = "c:\\test1.txt";
main()
{
FILE *in_file; /* input file */
/* character or EOF flag from input */
int *ch;
clrscr();
in_file = fopen(file_name, "r");
if ( in_file == NULL ) {
printf("Cannot open %s\n", file_name);
exit(0);
}
while (1) {
ch = fgetc(in_file);
if ( ch == EOF )
break;
ch++;
}
fclose(in_file);
/* this is the part where I want to store it in prog because I will be using prog in my other functions. */
}