NO ERROR but still doesnt works !! file mode open issue !!

ON compilation it shows no error but it doesnt runs !!


#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <sstream>


using namespace std;
int main ()
{

FILE *pFile1;
FILE *ff;
FILE *pFile;
int a[2000],A[2000];
float b[2000],c[2000],d[2000],e[2000],B[2000],C[2000],D[2000],E[2000];

string st1 = "data";
string ext = ".dat";
string filename;


for(int j = 1; j < 30; j++)
{
stringstream ss;
ss << j;
filename = st1 + ss.str() + ext;
const char * cs = filename.c_str ();
cout<<cs<<endl;
cout << filename <<" opened\n";
pFile1 = fopen (cs,"r");
if (pFile1==NULL)
{cout<<"oh my god "<<endl;}
int z=0;
while (!feof(pFile1))
{
fscanf (pFile1, "%d", &A[z]);
fscanf (pFile1, "%f", &B[z]);
fscanf (pFile1, "%f", &C[z]);
fscanf (pFile1, "%f", &D[z]);
fscanf (pFile1, "%f", &E[z]);
z++;
}
cout<<"z="<<z;
fclose (pFile1);



}
return 0;
}
Last edited on
ON compilation it shows no error but it doesnt runs !!


Perhaps you could be more descriptive than "it doesnt runs !!" What makes you think it's not working?

One problem might be that you check to see if pFile1 is NULL, and output a message if it is, but, if it is, you still use it in the loop, likely causing a crash and definitely undefined behavior.
Topic archived. No new replies allowed.