Hi!
I have huge problems with this (Text) function and the strlen function. When I use them together the exception is thrown when I run the program in the DEBUG configuration manager. In the RELEASE c.m. everything is OK.
Code:
# define STPFILE "setup.cfg"
typedef struct
{
char LanguageFile[30];
} Setup;
char *ReadLanguage () // function reads a language file from the file "setup.cfg"
{
FILE *fin = NULL;
Setup file;
if ((fin = fopen (STPFILE, "rb")) != NULL)
{
fread (&file, sizeof (Setup), 1, fin);
fclose (fin);
return file.LanguageFile;
}
else return NULL;
}
char *Text (char File[], short Line)
{
FILE *fin = NULL;
short Lines = 0, UC = 0;
char Character, *Text1 = NULL, *temp = NULL;
if ((fin = fopen (File, "rt")) != NULL)
{
Text1 = malloc (sizeof (char) * 100);
if (Text1 == NULL) exit (1);
temp = Text1;
while (fscanf (fin, "%c", &Character) != EOF)
{
if (Character == '#') Lines++; // counting lines
if (Lines == Line)
{
if (Character != '\n')
{
UC++;
}
if (UC >= 8)
{
if ( (Character == ';') || (Character == '\n') ) break;
*(temp++) = Character;
}
}
}
*temp = 0;
fclose (fin);
return Text1;
}
else
{
return NULL;
}
}
Text and strlen function together:
Code:
char *Text1 = Text (ReadLanguage (), 1); // functions "Text" and ReadLanguage() are called.
// Function Text reads the first line in the "ReadLanguage ()" file
short Text1Length = (short) strlen (Text1) + 1; <- here is thrown the exception
This is what I get in .NET:
" Unhandled exception at 0x00419d10 in Text.exe: 0xC0000005: Access violation reading location 0x00000000. "
But when I use strlen in a different way, something like this, everything is OK (in the DEBUG c.m.).
Code:
short Text1Length = 0;
Text1Length = (short) strlen ("HELLO") + 1; <- the exception is not thrown
What could be wrong? Is it the Text function?
I would be very grateful for your answers.
I'm using Visual Studio C++.NET on Win2k.