I see some related questions have been asked, but they're either too advanced for me to grasp or lacking a step-by-step guide from start to finish (most of them end up being insider talk of their own experiment results). OK here it is, given this simple program:
#include <stdio.h>
#include <string.h>
int main()
{
FILE * f;
char buffer[100];
memset(buffer, 0, 100);
fun();
f = fopen("main.cpp", "r");
fread(buffer, 1, 99, f);
printf(buffer);
fclose(f);
return 0;
}
What it does is basically print itself (assume file name is main.cpp).
Question
How can I have it print another file, say foobar.txt without modifying the source code? It has something to do with running it through VS's, stepping through the functions and hijacking the FILE pointer right before fread() is called. No need to worry about leaking resources by calling fclose().
I tried the simple f = fopen("foobar.txt", "r") which gave
CXX0017: Error: symbol "fopen" not found
Any ideas?