Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef enum {false, true} bool;
- bool dupcheck_code(char a[11], int k) { /* check duplicate a in array bkinstck[].code which have k elements */
- int i;
- for (i = 0; i<k; i++) {
- if (strcmp(bkinstck[i].code, a) == 0) {
- return(true);
- }
- }
- return(false);
- }
- void input_code(int i) { /* input bkinstck[i].code */
- char a[11];
- while (1) {
- printf(" Enter code (enter STOP to stop): ");
- fflush(stdin);
- gets(a);
- //scanf("%[^\n]", a);
- if ((strlen(a) > 0) && (strlen(a) <= 10)) {
- if (dupcheck_code(a, i) == true) {
- printf(" The code %s already exists, please re-enter!\n", a);
- }
- else {
- strcpy(bkinstck[i].code, a);
- break;
- }
- }
- else {
- printf(" Invalid code, please re-enter!\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement