Hello, I recently got Visual C++ and I am having a problem with it. I have a text file I want to input into my program but I don't know the directory Visual C++ reads files from or how to find out. I'm sure it's obvious but I can't figure it out.
I also have another problem. Before I got Visual C++ I had some trouble with taking input from a file and putting it into an array. The text file consisted of only 1's and 0's with no whitespace or any other characters. Here is the code segment:
I tried a few fixes and ended up with some unexpected outputs but I can't seem to get it to work.Code:#include <stdio.h>
#define LENGTH 2000
FILE *fp;
int output[LENGTH];
...
int temp;
int index = 0;
if((fp = fopen("test.txt", "r")) == NULL) {
printf("Error opening file.");
exit(1);
}
for (;;) {
if ((temp = fgetc(fp)) == EOF) break;
if (temp) test[index] = 1;
else test[index] = 0;
printf("%d %d\n" , index, test[index]);
if ((++index) > LENGTH-1) break;
}
fclose(fp);