Original Post
Hi, I''m creating a message generator that can show a message depending on the message type, i.e. if its an error message, then a MesageBox(); gets displayed, if help, then status message, if ordinary text, then DrawText();
This is no prob, but I hav some code to hold these messages and I am testing it out in C, but I''d like to pare it down, without losing the struct, can anyone help ???
// message.c
// Daniel J. Somers
#include
#include
#include
#include
void showmessage(char msg[]);
// messages structure
struct SCREENMESSAGE
{
char *error[2];
char *question[2];
char *text[2];
}*message;
void main()
{
char error1[]="Cannot initialise game.\0";
char error2[]="Game has already been loaded.\0";
char question1[]="Are you sure ?\0";
char question2[]="Yes or No ?\0";
char text1[]="Loading...\0";
char text2[]="Exiting...\0";
message=malloc(sizeof(struct SCREENMESSAGE));
message->error[0]=malloc(sizeof(error1));
message->error[1]=malloc(sizeof(error2));
message->question[0]=malloc(sizeof(question1));
message->question[1]=malloc(sizeof(question2));
message->text[0]=malloc(sizeof(text1));
message->text[1]=malloc(sizeof(text2));
strcpy(message->error[0],error1);
strcpy(message->error[1],error2);
strcpy(message->question[0],question1);
strcpy(message->question[1],question2);
strcpy(message->text[0],text1);
strcpy(message->text[1],text2);
showmessage(message->question[0]);
showmessage(message->question[1]);
showmessage(message->error[0]);
showmessage(message->error[1]);
showmessage(message->text[0]);
showmessage(message->text[1]);
getch();
free(message);
}
void showmessage(char msg[])
{
unsigned short index;
// search messages for the message type
for(index=0; index<=1; index++)
{
// compare msg with messages
if(strcmp(msg,message->error[index])==0)
{
// show error message box
printf("%s",msg);
break;
}
// compare msg with messages
if(strcmp(msg,message->question[index])==0)
{
// show question message box
printf("%s",msg);
break;
}
// compare msg with messages
if(strcmp(msg,message->text[index])==0)
{
printf("%s",msg);
break;
}
}
}