// AB 10 형태의 자료를 입력받는다. void input() { scanf("%d %d", &V, &E); int a, b, c; char vertex[3]; int i; for (i = 0; i < E; i++) { scanf("%s %d", vertex, &c); a = name2int(vertex[0]); b = name2int(vertex[1]); edge[i].v1 = a; edge[i].v2 = b; edge[i].weight = c; } }
void input_adjmatrix(int a[][MAX_VERTEX], int *V, int *E) { char vertex[3]; int i, j, k; printf("\nInput number of Vertex & Edge\n"); fscanf(fp, "%d %d", V, E); /* input no of Vertex & Edge */ for (i = 0; i < *V; i++) for (j = 0; j < *E; j++) a[i][j] = 0; for (i = 0; i < *V; i++) a[i][i] = 1; /* assume reflexive */ for (k = 0; k < *E; k++) { printf("\n Input two Vertex consist of Edge -> "); fscanf(fp, "%s", vertex); i = name2int(vertex[0]); j = name2int(vertex[1]); a[i][j] = 1; /* symmetry for undirected graph */ a[j][i] = 1; } }
void input_adjlist(node *a[], int *V, int *E) { char vertex[3]; int i, j; node *t; printf("\nInput number of Vertex & Edge\n"); fscanf(fp, "%d %d", V, E); /* input no of Vertex & Edge */ for (i = 0; i < *V; i++) /* initialize nodes */ a[i] = NULL; for (j = 0; j < *E; j++) { printf("\nInput two Vertex consist of Edge -> "); fscanf(fp,"%s", vertex); i = name2int(vertex[0]); /* asymmetry for directed graph */ t = (node*)malloc(sizeof(node)); t->vertex = name2int(vertex[1]); t->next = a[i]; a[i] = t; } }
void input_adjlist(head net[], int *V, int *E) { /* input network */ int i, j; char edge[3]; node *t; printf("\nInput number of Vertex & Edge\n"); fscanf(fp, "%d %d", V, E); /* input no of Vertex & Edge */ set_count_zero(network, *V); for (i = 0; i < *V; i++) net[i].next = NULL; for (j = 0; j < *E; j++) { printf("\nInput two Vertex consist of Edge -> "); fscanf(fp, "%s", edge); t = (node*)malloc(sizeof(node)); t->vertex = name2int(edge[1]); t->next = net[name2int(edge[0])].next; net[name2int(edge[0])].next = t; } }
void rd_field(struct field *f, char *val, int merge) { struct wscons_keymap *mp; struct field_pc *pc; u_int u, r, fr; char *p; int i; switch (f->format) { case FMT_UINT: if (sscanf(val, "%u", &u) != 1) errx(1, "%s: not a number", val); if (merge) *((u_int *) f->valp) += u; else *((u_int *) f->valp) = u; break; case FMT_INT: if (sscanf(val, "%d", &i) != 1) errx(1, "%s: not a number", val); if (merge) *((int *) f->valp) += i; else *((int *) f->valp) = i; break; case FMT_BOOL: if (*val != 'o' || (val[1] != 'n' && (val[1] != 'f' || val[2] != 'f'))) errx(1, "%s: invalid value (on/off)", val); *((u_int *) f->valp) = val[1] == 'n'? 1 : 0; break; case FMT_PC: fr = 0; if ((i = sscanf(val, "%u.%u%%", &u, &fr)) != 2 && i != 1) errx(1, "%s: not a valid number", val); pc = f->valp; r = pc->max - pc->min; i = pc->min + (r * u) / 100 + (r * fr) / 100 / 100; if (merge == '+') pc->cur += i; else if (merge == '-') pc->cur -= i; else pc->cur = i; if (pc->cur > pc->max) pc->cur = pc->max; if (pc->cur < pc->min) pc->cur = pc->min; break; case FMT_KBDENC: p = strchr(val, '.'); if (p != NULL) *p++ = '\0'; i = name2int(val, kbdenc_tab, TABLEN(kbdenc_tab)); if (i == -1) errx(1, "%s: not a valid encoding", val); *((u_int *) f->valp) = i; while (p) { val = p; p = strchr(p, '.'); if (p != NULL) *p++ = '\0'; i = name2int(val, kbdvar_tab, TABLEN(kbdvar_tab)); if (i == -1) errx(1, "%s: not a valid variant", val); *((u_int *) f->valp) |= i; } break; case FMT_KBMAP: if (! merge) kbmap.maplen = 0; map_scan_setinput(val); yyparse(); if (merge) { if (newkbmap.maplen < kbmap.maplen) newkbmap.maplen = kbmap.maplen; for (i = 0; i < kbmap.maplen; i++) { mp = newkbmap.map + i; if (mp->command == KS_voidSymbol && mp->group1[0] == KS_voidSymbol && mp->group1[1] == KS_voidSymbol && mp->group2[0] == KS_voidSymbol && mp->group2[1] == KS_voidSymbol) *mp = kbmap.map[i]; } } kbmap.maplen = newkbmap.maplen; bcopy(newkbmap.map, kbmap.map, kbmap.maplen*sizeof(struct wscons_keymap)); break; case FMT_SCALE: { const char *errstr = 0; /* Unspecified values default to 0. */ bzero(&wmcoords, sizeof(wmcoords)); val = (void *)strtok(val, ","); if (val != NULL) { wmcoords.minx = (int)strtonum(val, -32768, 32767, &errstr); val = (void *)strtok(NULL, ","); } if (!errstr && val != NULL) { wmcoords.maxx = (int)strtonum(val, -32768, 32767, &errstr); val = (void *)strtok(NULL, ","); } if (!errstr && val != NULL) { wmcoords.miny = (int)strtonum(val, -32768, 32767, &errstr); val = (void *)strtok(NULL, ","); } if (!errstr && val != NULL) { wmcoords.maxy = (int)strtonum(val, -32768, 32767, &errstr); val = (void *)strtok(NULL, ","); } if (!errstr && val != NULL) { wmcoords.swapxy = (int)strtonum(val, -32768, 32767, &errstr); val = (void *)strtok(NULL, ","); } if (!errstr && val != NULL) { wmcoords.resx = (int)strtonum(val, 0, 32767, &errstr); val = (void *)strtok(NULL, ","); } if (!errstr && val != NULL) { wmcoords.resy = (int)strtonum(val, 0, 32767, &errstr); val = (void *)strtok(NULL, ","); } if (errstr) errx(1, "calibration value is %s", errstr); if (val != NULL) errx(1, "too many calibration values"); break; } case FMT_STRING: strlcpy(f->valp, val, WSFONT_NAME_SIZE); break; default: errx(1, "internal error: rd_field: no format %d", f->format); break; } }