Hi,
I am reading a text file which has 4 columns into a 3D array.
My code is compiling...... ..but cant see the output. Shows .exe file stopped working.
My code is as follows:
//#include "stdafx.h"
#include<iostre am>
#include<string >
#include<fstrea m>
using namespace std;
int function(const char *fName, int img_3D[][128][128])
{
int a[5],i,j;
FILE *fp=fopen("abc. txt","r");
while(!feof(fp) )
{
cout<<"file opened";
for(i=0;i<4;i++ )
fscanf(fp,"%d", &a[i]);
if(feof(fp)) break;
if(a[0]>126||a[1]>126||a[2]>126)
{
printf("Error in input");
return(-1);
}
//printf("%d %d %d %d\n",a[0],a[1],a[2],a[3]);
img_3D[a[0]+1][a[1]+1][a[2]+1]=a[3];
}
fclose(fp);
}
int print(const char *fName,int img_3D[][128][128])
{
int a[5],i,j,fee;
FILE *fp=fopen("abc. txt","r");
while(!feof(fp) )
{
for(i=0;i<4;i++ )
fscanf(fp,"%d", &a[i]);
if(feof(fp)) break;
if(a[0]>126||a[1]>126||a[2]>126)
{
printf("Error in input");
return(-1);
}
printf("%d\n",i mg_3D[a[0]+1][a[1]+1][a[2]+1]);
}
fclose(fp);
}
int main()
{
int a[128][128][128];
function("abc.t xt",a);
print("abc.txt" ,a);
return 0;
}
In my text file, I will be skipping the first row, then start reading from the 2nd row. My text files contains a set of integers.
Though its compiling, why cant I see the output?
Pls help.
Thanks!!
I am reading a text file which has 4 columns into a 3D array.
My code is compiling...... ..but cant see the output. Shows .exe file stopped working.
My code is as follows:
//#include "stdafx.h"
#include<iostre am>
#include<string >
#include<fstrea m>
using namespace std;
int function(const char *fName, int img_3D[][128][128])
{
int a[5],i,j;
FILE *fp=fopen("abc. txt","r");
while(!feof(fp) )
{
cout<<"file opened";
for(i=0;i<4;i++ )
fscanf(fp,"%d", &a[i]);
if(feof(fp)) break;
if(a[0]>126||a[1]>126||a[2]>126)
{
printf("Error in input");
return(-1);
}
//printf("%d %d %d %d\n",a[0],a[1],a[2],a[3]);
img_3D[a[0]+1][a[1]+1][a[2]+1]=a[3];
}
fclose(fp);
}
int print(const char *fName,int img_3D[][128][128])
{
int a[5],i,j,fee;
FILE *fp=fopen("abc. txt","r");
while(!feof(fp) )
{
for(i=0;i<4;i++ )
fscanf(fp,"%d", &a[i]);
if(feof(fp)) break;
if(a[0]>126||a[1]>126||a[2]>126)
{
printf("Error in input");
return(-1);
}
printf("%d\n",i mg_3D[a[0]+1][a[1]+1][a[2]+1]);
}
fclose(fp);
}
int main()
{
int a[128][128][128];
function("abc.t xt",a);
print("abc.txt" ,a);
return 0;
}
In my text file, I will be skipping the first row, then start reading from the 2nd row. My text files contains a set of integers.
Though its compiling, why cant I see the output?
Pls help.
Thanks!!
Comment