Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

Program in C Language - How to include a file directory for text file to complie

$
0
0

I have a simple C program going in my Microsoft Visual C++ 2010 Express which simply is:

int main(int argc, char *argv[]) {

int n;

FILE *ifp;
ifp = fopen(argv[1], "r");

fscanf(ifp, "%d", &n);
printf("%d", n);

fclose(ifp);
return 0;

}

I also have a text file ready, with a simple number written, but don't know how to go about linking the two so that the C program can compile and read my text file. I know that I have to place the text file in the root project folder, or really anywhere as long as I mention which folder to read from. But this is exactly the problem. I don't really know how to go about this. 

I'm still starting out with programming, so really precise directions would help me best.. for example, fixing this problem by.. Open the Solution Explorer tab, right click on the project name, click properties, under C/C++, click change directory, and....


Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>