Page 1 of 1

memory write access violation error...???

Posted: Thu Sep 23, 2004 2:03 am
by Lou-saydus
uh will thats about it.....
here is the code

Code: Select all

/* Logs 0.1
Tuesday, September, 1:57 pm, 2004

Logs logins.
thats about it...
*/
#include <stdio.h>
#include <time.h>

FILE CreateLog(char filename[]);
void Log(char string[]);
char GetDateTime(char string[]);
int  Password(void);


main()
{
	Password();
}

/* Function CreateLog definition */
FILE CreateLog(char filename[])
{
	FILE *fptr;
   fptr = fopen(filename, "a+");

   return *fptr;
}
/* Function Log definition */
void Log(char string[], FILE *fptr)
{
	fputs(string, fptr);
}
/* Function GetDateTime definition */
char GetDateTime(void)
{
	time_t timeT;
   char string[90];

   time(&timeT);
   asctime(localtime(&timeT));
   *string = timeT;
   return *string;
}
/* Function Password definition */
int Password(void)
{
	char pass[8], string[90], filename[] = "Login.log", LogS[90], TESTLOG[] = "TEST";
   FILE *fptr;
   int reval, c;

   *fptr = CreateLog(filename);
   *LogS = GetDateTime();
	printf("Enter password.\n", pass);
   scanf("%s", &pass);
   printf("pass = %s", pass);

   if (pass == "123"){
   	printf("Access granted.\nLogin clear.\n");
      printf("Ready? (Y/N)\n");
      	while(c != 'Y'){
      	c = getc(stdin);
      	}
      reval = 1;
   } else {
   	Log(TESTLOG, fptr);
		printf("Access denied.\nLogin attempt has been loged.\n");
   	printf("Ready? (Y/N)\n");
      	while(c != 'Y'){
      	c = getc(stdin);
      	}
      reval = 0;
      }

   return reval;
}
in the "Password" function declaration the while statement gives
me a error. but if i change it to a for statement it dosnt.

any one know whats up?

Posted: Thu Sep 23, 2004 2:55 am
by jamesblonde001
same error occur when password is correct?
can you step through the code at runtime? If so what happens just after the while?

I dunno much bout C or C++ and my programming is 5 years rusty...
Hope this helps a bit.

Posted: Thu Sep 23, 2004 10:23 pm
by Lou-saydus
at build time i get this error.

Posted: Fri Sep 24, 2004 7:53 am
by Remdul
What kind of error?

Posted: Fri Sep 24, 2004 5:37 pm
by Lou-saydus
Thread stopped
C:\BC5\BIN\Logs.exe: Fault:
access violation at 0x401136:
write of address 0x0


ok only