Thread: Help doing an e-mail program in c...

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    45

    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:
    Code:
    From: [email protected]
    to: [email protected]
    Date: ....
    Subject: hfdhrt
    Message: fdhdh
    
    From: [email protected]
    to: [email protected]
    Date: ....
    Subject: hfdhrt
    Message: fdhdh
    
    From: [email protected]
    to: [email protected]
    Date: ....
    Subject: hfdhrt
    Message: fdhdh
    --------------

    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.
    Last edited by Tyler_Durden; 12-29-2004 at 04:25 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM