2017년 5월 30일 화요일

[Open S/W] Source codes we worked on May 30

Source codes

[store.c]===========================================================



#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "mylib.h"

struct address* store(i, top)
struct address* i;
struct address* top;
{

}

[mylib.h]===========================================================

#ifndef MYLIB_H_
#define MYLIB_H_

struct address {
    char name[40];
    char zip[10];
    struct address *next;
} list_entry;

extern struct address* start;
extern struct address* last;

int  menuSelect(void);
void enter(void);
struct address* store(struct address* i, struct address* top);

#endif

[main.c]===========================================================

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mylib.h"

int main(void)
{
    int choice;

    for(;;) {
       
        choice = menuSelect();
        
        switch(choice) {
            case 1:
                   enter();
                   break;
            case 2:
                   break;
            case 7:
                   exit(0);
                   break;
        }

    }
    return 0;
}

[enter.c]===========================================================

#include <stdio.h>
#include "mylib.h"

void enter(void)
{
    printf("\n enter() is called ....\n");
}

[menu.c]===========================================================

#include <stdio.h>
#include <stdlib.h>
#include "mylib.h"

int menuSelect(void)
{
    char select[80];
    int  num;

    do {
           printf("=================================\n");
           printf("Welcome to the PNU Mailing System\n");
           printf("1. Enter a name\n");
           printf("2. Delete a name\n");
           printf("7. Exit\n"); 
           printf("=================================\n");

           printf(">>> Enter your choice: ");
           fgets(select, 80, stdin);
           num = atoi(select);

    } while (num < 0 || num > 7);

    return num;
}

[Makefile]======================================================

all: mailing

mailing: main.c menu.o enter.o store.o
 gcc -o mailing main.c menu.o enter.o store.o

menu.o:
 gcc -c menu.c 

enter.o:
 gcc -c enter.c

store.o:
 gcc -c store.c

clean:
 rm -rf *.o