0

I am trying to load a data file into my program.

 fp = fopen("data.txt", "r");
//printf("\nfile check: %d", fp);

printf("Walmart/Sams' Club Stock Prices: ");
count = 0; 
while (fscanf(fp, "%-1.2f", &data2[count]) != EOF) 
{
    printf("%f ", data2[count]);

    { count = count + 1; }
}

However, it can't find the file. Is there somewhere I have to put it for it to be read?

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
  • _"However, it can't find the file."_ Are you sure it resides in the same directory that's the current working directory of your program? You can put a full path instead, to see if it's working. Hint: Visual Studio usually runs the program in the `Debug` directory of your project, unless you configure a different path in the project settings. Nothing to do with _OpenFrameworks_, I removed the misleading tag. – πάντα ῥεῖ Oct 15 '20 at 23:33
  • Since you are programming in C++, you should consider using `std::ifstream`. The extraction operator is overloaded for many types. You can also overload the extraction operator for your classes. You can't overload `fscanf` for custom classes. – Thomas Matthews Oct 15 '20 at 23:48

0 Answers0