#include #include #include // This code demonstrates how to handle path names when opening files stores in // a directory that is not the current working directory. // // In order to run this code successfully you must create a file named data.txt in // the local directory c:\temp\CprE_185 int main() { FILE* fp; char path[1024]; // the full path to the file will be stored here char dir[] = "C:\\temp\\CprE_185\\"; // remember that \ is an escape character. Use \\ char fname[] = "data.txt"; strcpy(path, dir); // copy dir into path strcat(path, fname); // concatenate path (i.e., dir) and fname; store the result in path. fp = fopen(path, "r"); // open the file for reading if( fp == NULL ) { printf("File [%s] not found!\n", path); } else { int a, b; fscanf(fp, "%d %d", &a, &b); // read 2 ints printf("a=%d, b=%d\n", a, b); // print them fclose(fp); } system("pause"); }