Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "r1.h"
- static void s_view(T_TLIST *p_tlist) {
- int i;
- T_TINFO *p;
- for (i = 0; i < p_tlist->num_tinfo; i++) {
- p = &p_tlist->tinfo[i];
- printf("[%5d]%15s(%15s),%2d\n", p->no, p->name, p->affiliation, p->student);
- }
- }
- static void s_update(T_TLIST *p_tlist) {
- char update[SIZE_STR];
- int no;
- T_TINFO *p;
- printf("Input No. : ");
- key_in_s(update, SIZE_STR);
- no = atoi(update);
- if (no < 0 || p_tlist->num_tinfo <= no) {
- printf("%d is not found\n", no);
- return;
- }
- p = &p_tlist->tinfo[no];
- printf("Input Name [%s]: ", p->name);
- key_in_s(p->name, SIZE_STR);
- printf("Input Affiliation [%s]: ", p->affiliation);
- key_in_s(p->affiliation, SIZE_STR);
- printf("Input Student(1)/other[%d]: ", p->student);
- p->student = key_in_c() - '0';
- }
- static void s_append(T_TLIST *p_tlist) {
- T_TINFO *p;
- p = &p_tlist->tinfo[p_tlist->num_tinfo];
- p->no = p_tlist->num_tinfo++;
- printf("Input Name: ");
- key_in_s(p->name, SIZE_STR);
- printf("Input Affiliation: ");
- key_in_s(p->affiliation, SIZE_STR);
- printf("Input Student(1)/other: ");
- p->student = key_in_c() - '0';
- }
- static void s_delete(T_TLIST *p_tlist) {
- char delete[SIZE_STR];
- int i, n;
- T_TINFO *p, *q;
- printf("Input No.: ");
- key_in_s(delete, SIZE_STR);
- n = atoi(delete);
- if (n < 0 || p_tlist->num_tinfo <= n) return;
- p_tlist->num_tinfo--;
- for (i = n; i < NUM_TINFO - 1; i++) {
- p = &p_tlist->tinfo[i];
- q = &p_tlist->tinfo[i + 1];
- memcpy(p, q, sizeof(T_TINFO));
- p->no--;
- }
- }
- int main(void) {
- char c;
- T_TLIST tlist;
- memset(&tlist, '\0', sizeof(tlist));
- while (1) {
- printf("\n(L)oad, (V)iew, (A)ppend, (D)elete, (U)pdate, (S)ave, (Q)uit: ");
- c = key_in_c();
- if (c == 'L' || c == 'l') {
- s_load(&tlist);
- } else if (c == 'V' || c == 'v') {
- s_view(&tlist);
- } else if (c == 'A' || c == 'a') {
- s_append(&tlist);
- } else if (c == 'D' || c == 'd') {
- s_delete(&tlist);
- } else if (c == 'U' || c == 'u') {
- s_update(&tlist);
- } else if (c == 'S' || c == 's') {
- s_save(&tlist);
- } else if (c == 'Q' || c == 'q') {
- break;
- } else {
- fprintf(stderr, "Unsupported Character: %c\n", c);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement