M
Marcus Jacobs
Dear Group
I have encountered a problem with fclose and I am wondering if anyone
could provide some insight about this problem to me. Currently, I am
working on a small personal project that is requiring for me to alter
some existing code to a program. While running the unaltered code, I
kept encountering an application (The exception unknown software
exception(0xc00000fd) etc. .. etc... etc... I am running W2K Pro).
Through a bit of debugging I singled out where the problem is
occuring. It is occuring when it attemps to close a file that had
previously been open. While tinkering with this problem, I noticed
that no error occured while closing when I manually entered the file
name into the source code. The error only occured when the user has to
key-in the file name from a command line (this is how I wish for the
program to run). What is causing this problem? Below I have provided
some source code to the function that is causing the problem. Here is
the version of the source in which no error occurs. I have set the
string, finc_name, to the file name "all.inc". Normally, the array is
set to a default of size 80 similar to fpov_name. I have also
commented out the portion of the code which prompts the user to key-in
the file name.
Thanks
Marcus D. Jacobs
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "numtypes.h"
/* #include "numtable.h"*/
typedef struct
{
Word x,r,g,b;
} colorinfo;
FILE *finc, *fpov, *frad;
char ch, frad_name[80], finc_name[] = "all.inc", fpov_name[80] ,
is_num;
char *pov_word;
char chpov , colorend='f';
colorinfo color;
Word texture[2600];
void reads_triangle(Word pov_num);
void reads_smoothtriangle(Word pov_num);
void reads_inc(void);
void reads_color(void);
void reads_texture(void);
main(void)
{
int m=1, n, j;
char chtext, finish;
char *inc_word;
int isize;
int j2;
/*
printf("Enter POV include file name ( *.inc ) : ");
gets(finc_name);
printf("\n");
*/
finc=fopen(finc_name, "r");
chtext = getc(finc);
if (finc==NULL)
{ printf(" Can't open %s\n", finc);
exit(EXIT_FAILURE);
}
while (chtext != EOF )
{
finish ='f';
if ( ( inc_word = malloc(25)) == NULL )
{ printf("Out of memory");
exit(EXIT_FAILURE);;
}
while (isspace(chtext)) chtext = getc(finc);
j=0;
while (chtext != EOF && isspace(chtext) == 0)
{ inc_word[j++] = chtext;
chtext = getc(finc);
}
inc_word[j] = '\0';
if (strcmp(inc_word, "texture") == 0 && finish == 'f')
{ while (isspace(chtext)) chtext = getc(finc);
n=0;
chtext = getc(finc);
while ( chtext != '}' )
{
texture[m][n++] = chtext;
chtext = getc(finc);
}
texture[m][n] = '\0';
/* printf(" texture = %s ", texture[m]);*/
m++;
finish = 't';
}
free(inc_word);
}
fclose(finc);
}
I have encountered a problem with fclose and I am wondering if anyone
could provide some insight about this problem to me. Currently, I am
working on a small personal project that is requiring for me to alter
some existing code to a program. While running the unaltered code, I
kept encountering an application (The exception unknown software
exception(0xc00000fd) etc. .. etc... etc... I am running W2K Pro).
Through a bit of debugging I singled out where the problem is
occuring. It is occuring when it attemps to close a file that had
previously been open. While tinkering with this problem, I noticed
that no error occured while closing when I manually entered the file
name into the source code. The error only occured when the user has to
key-in the file name from a command line (this is how I wish for the
program to run). What is causing this problem? Below I have provided
some source code to the function that is causing the problem. Here is
the version of the source in which no error occurs. I have set the
string, finc_name, to the file name "all.inc". Normally, the array is
set to a default of size 80 similar to fpov_name. I have also
commented out the portion of the code which prompts the user to key-in
the file name.
Thanks
Marcus D. Jacobs
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "numtypes.h"
/* #include "numtable.h"*/
typedef struct
{
Word x,r,g,b;
} colorinfo;
FILE *finc, *fpov, *frad;
char ch, frad_name[80], finc_name[] = "all.inc", fpov_name[80] ,
is_num;
char *pov_word;
char chpov , colorend='f';
colorinfo color;
Word texture[2600];
void reads_triangle(Word pov_num);
void reads_smoothtriangle(Word pov_num);
void reads_inc(void);
void reads_color(void);
void reads_texture(void);
main(void)
{
int m=1, n, j;
char chtext, finish;
char *inc_word;
int isize;
int j2;
/*
printf("Enter POV include file name ( *.inc ) : ");
gets(finc_name);
printf("\n");
*/
finc=fopen(finc_name, "r");
chtext = getc(finc);
if (finc==NULL)
{ printf(" Can't open %s\n", finc);
exit(EXIT_FAILURE);
}
while (chtext != EOF )
{
finish ='f';
if ( ( inc_word = malloc(25)) == NULL )
{ printf("Out of memory");
exit(EXIT_FAILURE);;
}
while (isspace(chtext)) chtext = getc(finc);
j=0;
while (chtext != EOF && isspace(chtext) == 0)
{ inc_word[j++] = chtext;
chtext = getc(finc);
}
inc_word[j] = '\0';
if (strcmp(inc_word, "texture") == 0 && finish == 'f')
{ while (isspace(chtext)) chtext = getc(finc);
n=0;
chtext = getc(finc);
while ( chtext != '}' )
{
texture[m][n++] = chtext;
chtext = getc(finc);
}
texture[m][n] = '\0';
/* printf(" texture = %s ", texture[m]);*/
m++;
finish = 't';
}
free(inc_word);
}
fclose(finc);
}