Code:
#ifndef PROGMAIL_H_INCLUDED
#define PROGMAIL_H_INCLUDED
// this is progmail.h
typedef struct mail
{
char from[120];
char to[120];
char sub[120];
char msg[120];
} MAIL;
void comandom(MAIL *m);
void comandoC(MAIL *m);
void comandoL(MAIL *m);
#endif
Code:
// this is progmail.c (part of it)
#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");
// add rest of help text here
return 0;
}
int main (){
char c;
char input[BUFSIZ];
MAIL mailmessage;
fopen("mail.txt","r");
printf("E-mail program.\n");
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(&mailmessage);break;
case 'L':comandoL(&mailmessage);break;
default: printf("Unknown command!\n");break;
}
}while (c!='x');
return 0;
}
Code:
// this is comandom.c
#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)
{
printf("From: \n"); fgets(ptr->from,sizeof ptr->from, stdin);
printf("To: \n"); fgets(ptr->to,sizeof ptr->to, stdin);
printf("Subject:\n"); fgets(ptr->sub,sizeof ptr->sub, stdin);
printf("Message:\n"); fgets(ptr->msg,sizeof ptr->msg, stdin);
}
Code:
// this is comandoL.c
#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);
}
Notice progmail.h
It contains all the bits of information which need to be shared between all the source files in your project.
One of the first tasks in a programming exercise is simply making sure that you can input information to the program, and print it back again without doing anything else.
To this end, making sure comandom() and comandoL() work as expected is a useful first step.