I'm using Dev C btw.
We're basically trying to make a mail program? Logging in, sending mail to other registered users, etc.
Each "e-mail" must be dynamically allocated(through the use of linked lists).
The sendmail function takes:
the message details(mail data) like recipients, the subject and the message
the username of the account sending it
and the address of the first node of the linked list of accounts.
It encounters an access violation at the line where it says "while(temp->inbox->next != NULL)".
The program is 1031 lines long so i simply posted the function. If you need any other data, please ask and I will post that section of the program
Please help me resolve the problem
Code:
void sendmail(mail data, char username[], account *list)
{
int i=0;
account *temp;
inbox *message;
message = malloc(sizeof(inbox));
message->inbox = data;
message->next = NULL;
for(i=0;i<5;i++)
message->inbox.recipient[i].chara[0] = '\0';
strcpy(message->inbox.recipient[i].chara, username);
temp = NULL;
system("cls");
for(i=0;i<5;i++)
{
if(strlen(data.recipient[i].chara) > 0)
{
printf("%s - Message sending... ", data.recipient[i].chara);
switch(usercheck(list, data.recipient[i].chara))
{
case -1: printf("Error: Username too short.\n\n");
break;
case 2: printf("Error: Username too long.\n\n");
break;
case 3: printf("Error: Invalid username.\n\n");
break;
case 0: printf("Error: User does not exist.\n\n");
break;
case 1: temp = openmail(list, data.recipient[i].chara);
if(temp->inbox = NULL)
temp->inbox = message;
else
{
while(temp->inbox->next != NULL)
temp->inbox = temp->inbox->next;
temp->inbox->next = message;
temp->inbox->next->next = NULL;
printf("temp->inbox->next->inbox.recipient[i].chara = %s", temp->inbox->next->inbox.recipient[i].chara);
printf("Message sent! Time sent: %s\n\n", ctime(&data.timenow));
temp = NULL;
}
break;
}
}
}
}