I am using some code I got from github and I was struggling to read a text file. The code is meant to read in some dimensions from a list of boxes. Here's a snippet. Please let me know if I need to add more.
void inputboxlist(void)
{
short int n;
int errnum;
char lbl[5], dim1[5], dim2[5], dim3[5], boxn[5], strxx[5], stryy[5], strzz[5];
strcpy(strtemp, filename);
strcat(strtemp, ".txt");
if ( (ifp=fopen(strtemp,"r")) == NULL )
{
errnum = errno;
fprintf(stderr, "Value of errno: %d\n", errno);
printf("Cannot open file %s", strtemp);
fprintf(stderr, "Error opening file: %s\n", strerror( errnum ));
exit(1);
}
tbn = 1;
if ( fscanf(ifp,"%s %s %s",strxx, stryy, strzz) == EOF )
{
exit(1);
}
xx = atoi(strxx);
yy = atoi(stryy);
zz = atoi(strzz);
while ( fscanf(ifp,"%s %s %s %s %s",lbl,dim1,dim2,dim3,boxn) != EOF )
{
boxlist[tbn].dim1 = atoi(dim1);
boxlist[tbn].dim2 = atoi(dim2);
boxlist[tbn].dim3 = atoi(dim3);
boxlist[tbn].vol = boxlist[tbn].dim1 * boxlist[tbn].dim2 * boxlist[tbn].dim3;
n = atoi(boxn);
boxlist[tbn].n = n;
while (--n)
{
boxlist[tbn+n] = boxlist[tbn];
}
tbn = tbn+atoi(boxn);
}
--tbn;
fclose(ifp);
return;
}
I then did a debug and as soon as I ran the char line(5th) my variables list was filled with strange symbols as seen below. Anyone know why it's doing this?
= {0}
to each one of those char arrays to initialize them all to 0 if you'd like.