Originally Posted by
Sebastiani
post the entire program.
ok..so the entire program until now is this:
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 */
#include "progmail.h"
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,input[BUFSIZ];
MAIL mailmessage;
MAILR mailr;
printf("E-mail program.\n");
leficheiro(&mailr);
do{
putchar ('&');
fgets(input,BUFSIZ,stdin);
c = input[0];
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(&mailmessage);break;
case 'q':printf("ok\n");break;
case 'x':printf("Program shutting down!\n"); break;
case 'h':printf("ok\n");break;
case 'C':comandoC(&mailr);break;
case 'L':comandoL(&mailmessage);break;
default: printf("Unknown command -> %s \n",input);break;
}
}while (c!='x');
return 0;
}
comandoC.c
Code:
#include<stdio.h>
#define MAX 120
typedef struct mailr{
char from[MAX+1];
char to[MAX+1];
char sub[MAX+1];
char msg[MAX+1];
}MAILR;
void comandoC(MAILR *ptr){
printf("%s\n",ptr->from);
printf("%s\n",ptr->to);
printf("%s\n",ptr->sub);
printf("%s\n",ptr->msg);
puts("");
}
comandoL.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 */
#include "progmail.h"
void comandoL(MAIL *ptr)
{
printf("From: %s\n",ptr->from);
printf("To: %s\n",ptr->to);
printf("Subject:%s\n",ptr->sub);
printf("Message:%s\n",ptr->msg);
}
comandom.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 */
#include "progmail.h"
void comandom(MAIL *ptr)
{
FILE *fp;
fp = fopen("mail.txt","a");
printf("To: \n"); fgets(ptr->to,sizeof ptr->to, stdin);
fprintf(fp,"To:%s",ptr->to);
printf("From: \n"); fgets(ptr->from,sizeof ptr->from, stdin);
fprintf(fp,"From: %s",ptr->from);
printf("Subject:\n"); fgets(ptr->sub,sizeof ptr->sub, stdin);
fprintf(fp,"Subject: %s",ptr->sub);
printf("Message:\n"); fgets(ptr->msg,sizeof ptr->msg, stdin);
fprintf(fp,"%s",ptr->msg);
fprintf(fp,"\n");
fclose(fp);
}
leficheiro.c
Code:
#include <stdio.h>
#include <string.h>
#include "progmail.h"
void leficheiro(MAILR *ptr)
{
FILE *fp;
fp = fopen("mail.txt","r");
fgets(ptr->to,50,fp);
fgets(ptr->from,50,fp);
fgets(ptr->sub,50,fp);
fgets(ptr->msg,50,fp);
fclose(fp);
}
mail.txt (example)
Code:
To:fdgd
From: geb
Subject: erg
regdfgdfgdfffsdg
To:dsgsdg
From: asdd
Subject: gfgd
fddfhgdfheshresh
ok, so what I am missing here is:
->to be able to insert the date and hour when each e-mail was written in the mail.txt...in comandom.c I need to be able to have the emails date too...
->Now I see that the mails can only be saved whern "q" is pressed.this is because the program has to work this way:
-you write the mails you want
-if you press "x" the mail.txt isn't modified and the program exits
-if you press "q" the mails are saved in "mail.txt" and the program exits
->I then need to be able to go to the struct that was made out of the file "mail.txt" and when "h" is pressed, to have this output on the screen:
Code:
& h /* h being inserted*/
> N 1 <to> <date> <subject>
N 2 <to2> <date2> <subject2>
N 3 <to3> <date3> <subject3>
->Then I have to have a command that deletes mails from the "mail.txt", and works like this:
comandod.c
Code:
& d2
& h
> N 1 <endereço da mensagem1> <data1> <titulo da mensagem1>
N 3 <endereço da mensagem3> <data3> <titulo da mensagem3>
&
typing "d2", erases the second mail in "mail.txt"....
->the last comand that needs to be done is "t" that when typed like this for example "t2" gets an out put like this on the screen:
Code:
To: gfsddsf
From : sgd
Date:dfsgd
Subject:dfgfewq
Message:sdfgdsfg
that means it shows the mail in the screen..
and that is all...lol...see if you can help me in any of these tasks, please..time is running out
PS - comandoL and comandoC are only to test the comandom capacity to save the info into structs, and the leficheiro capacity to read the file to a struct, respectively(sp?)