Help doing an e-mail program in c...
I have to do an email program for a homework assignment...here I give you what I have made so far..
ok..so what I did until now is this...
the main file is this one:
------------------------------(progmail.c)----
Code:
#include <stdio.h> /* para funcoes como printf, scanf, etc */
#include <stdlib.h> /* para a funcao exit */
#include <string.h> /* para funcoes relacionadas com strings */
#define DIMMAIN 20
void comandom(void);
void comandoC(void);
void comandoL(void);
int help(){
printf ("Help \n \n");
printf ("Mail Commands \n \n");
printf("------------------------------------------------------------------------\n");
printf("| t <message list> type messages
|\n");
printf("| d <message list> delete messages
|\n");
printf("| R <message list> reply to message senders
|\n");
printf("| r <message list> reply to message senders and all
recipients |\n");
printf("| m <user list> mail to specific users
|\n");
printf("| q quit, saving unresolved messages in mbox
|\n");
printf("| x quit, do not remove system mailbox
|\n");
printf("| h print out active message headers
|\n");
printf("------------------------------------------------------------------------\n");
return 0;
}
int main (){
char c;
fopen("mail.txt","r");
printf("E-mail program.\n");
do{
putchar ('&');
scanf("%s",&c);
switch (c)
{
case '?':help();break;
case 't':printf("ok\n");break;
case 'd':printf("ok\n");break;
case 'R':printf("ok\n");break;
case 'r':printf("ok\n");break;
case 'm':comandom();break;
case 'q':printf("ok\n");break;
case 'x':printf("Program shutting down!\n"); break;
case 'h':printf("ok\n");break;
case 'C':comandoC();break;
case 'L':comandoL();break;
default: printf("Unknown command!\n");break;
}
}while (c!='x');
return 0;
}
---------------------------------
my "m" command, which is supposed to ask you for the email informations is
this one:
----------------/comandom.c-----------
Code:
#include <stdio.h>
typedef struct mail
{
char from[120];
char to[120];
char sub[120];
char msg[120];
} MAIL;
void comandom(MAIL *ptr)
{
printf("From: \n"); gets(ptr->from);
printf("To: \n"); gets(ptr->to);
printf("Subject:\n"); gets(ptr->sub);
printf("Message:\n"); gets(ptr->msg);
}
------------------------------
then I have the command "q" which when pressed has to keep all the written
emails in a mail.txt fuile..I made this:
--------------(comandoq.c)------------
Code:
#include <stdio.h>
FILE *fp;
fp = fopen("mail.txt","a");
fprintf(fp,"From:%s\n",from);
fprintf(fp,"To:%s\n",to);
fprintf(fp,"Subject:%s\n",sub);
fprintf(fp,"Message:%s\n",msg);
fprintf(fp,"\n");
fclose(fp);
}
----------------
it's not complete so I woudl like you to help me, please.
the output of the mail.txt file has to be something like this:
--------------
kan you help me please?
next I have to do a command that shows in the program the to,date and
subject of each message in "mail.txt" like this:
& h
N 1 <endereço da mensagem1> <data1> <titulo da mensagem1>
N 2 <endereço da mensagem2> <data2> <titulo da mensagem2>
N 3 <endereço da mensagem3> <data3> <titulo da mensagem3>
...
thanks a lot, help me please, it's a case of life or death because I have to deliver it the 2nd of january...
EDIT - the main problem it's the segmentation fault in the comandom.c , and I need some help in comandoq.c, which when called has to save all the written e-mails in "mail.txt"...
thanks.