Пример #1
0
int main(int argc, char **argv) {
  char studentNames[20][20];
  char nameToRemove[10];
  int menuChoice;

  char username[10];
  char password[10];
  int authentic = 0;

  while (!authentic) {
    printf("%s", "Username: "******"%s", username);
    printf("%s", "Password: "******"%s", password);

    if (strcmp(username, "admin") != 0 || strcmp(password, "admin") != 0) {
      printf("%s\n", "Wrong admin credentials.");
    }
    else {
      authentic = 1;
    }
  }

  int lastNameIndex = -1;

  seteuid(0);

  FILE * in_file;

  in_file = fopen("students.txt", "r");

  int c;
  int listIdx = 0;

  while ((c =fgetc(in_file)) != EOF) {
    char name[20];
    int idx = 0;
    while (c != '\n' && c != EOF) {
      name[idx] = c;
      idx++;
      c = fgetc(in_file);
    }
    name[idx++] = '\0';
    printf("%s\n", name);
    strcpy(studentNames[listIdx], strcat(name, "\0"));
    lastNameIndex++;
    listIdx++;
  }

  while (menuChoice != '0') {

    printf("%s", "\n___DINSMORE SCHOLARSHIP - MANAGEMENT___ \nMenu:\n1: Add a student\n2: Remove a student\n3: Print students\n0: Exit\n\nChoice: ");
    menuChoice = getchar();

    if (menuChoice == '\n') menuChoice = getchar();

    if (menuChoice > '/' && menuChoice < '4') {
      if (menuChoice == '1') {
        printf("%s", "Student name: ");
        scanf("%s", studentNames[lastNameIndex + 1]);
        lastNameIndex++;
      }
      else if (menuChoice == '2') {
        printf("%s", "Enter name to remove: ");
        scanf("%s", nameToRemove);
        while (!nameInList(nameToRemove, studentNames)) {
          printf("%s\n", "Name not found. Try again (or q to quit): ");
          scanf("%s", nameToRemove);
          if (strcmp(nameToRemove, "q") == 0)
            break;
          else {
            if (nameInList(nameToRemove, studentNames)) {
              for (int i = 0; i < 20; i++) {
                if (strcmp(nameToRemove, studentNames[i]) == 0) {
                  strcpy(studentNames[i], "EMPTYSLOT");
                }
              }
            }
          }
        }
      }
      else if (menuChoice == '3') {
        printf("%s\n", "\nSTUDENTS IN LINE TO RECEIVE SCHOLARSHIP:");
        for (int i = 0; i <= lastNameIndex; i++) {
          printf(studentNames[i]);
          printf("\n");
        }
      }
    }
  }
  //menuChoice = 0 here
  fclose(in_file);
  FILE* out_file;

  out_file = fopen("students.txt", "w");

  for(int i = 0; i <= lastNameIndex; i++) {
    fprintf(out_file, "%s\n", studentNames[i]);
  }
  fclose(out_file);
}
Пример #2
0
int
main(int argc, char **argv)
{
    static char fname[] = "lsinfo/main";
    struct lsInfo *lsInfo;
    int i, cc, nnames;
    char *namebufs[256];
    char longFormat = FALSE;
    char rFlag = FALSE;
    char tFlag = FALSE;
    char mFlag = FALSE;
    char mmFlag = FALSE;
    int rc;

    rc = _i18n_init ( I18N_CAT_MIN );

    if (ls_initdebug(argv[0]) < 0) {
        ls_perror("ls_initdebug");
        exit(-1);
    }
    if (logclass & (LC_TRACE))
        ls_syslog(LOG_DEBUG, "%s: Entering this routine...", fname);

    while ((cc = getopt(argc, argv, "VhlrmMt")) != EOF) {
        switch(cc) {
            case 'V':
                fputs(_LS_VERSION_, stderr);
                exit(0);
            case 'l':
                longFormat = TRUE;
                break;
            case 'r':
                rFlag = TRUE;
                break;
            case 't':
                tFlag = TRUE;
                break;
            case 'm':
                mFlag = TRUE;
                break;
            case 'M':
                mFlag  = TRUE;
                mmFlag = TRUE;
                break;
            case 'h':
            default:
                usage(argv[0]);
        }
    }

    for (nnames=0; optind < argc; optind++, nnames++)
        namebufs[nnames] = argv[optind];

    if ((lsInfo = ls_info()) == NULL) {
	ls_perror("lsinfo");
        exit(-10);
    }


    if (!nnames && !rFlag && !mFlag && !tFlag && !mmFlag)
        rFlag = mFlag = tFlag = TRUE;
    else if (nnames)
        rFlag = TRUE;

    if (rFlag) {
        if (!longFormat) {
	    char *buf1, *buf2, *buf3, *buf4;

	    buf1 = putstr_(_i18n_msg_get(ls_catd,NL_SETN,1804, "RESOURCE_NAME")), /* catgets  1804  */
	    buf2 = putstr_(_i18n_msg_get(ls_catd,NL_SETN,1805, "  TYPE ")), /* catgets  1805  */
	    buf3 = putstr_(_i18n_msg_get(ls_catd,NL_SETN,1806, "ORDER")), /* catgets  1806  */
	    buf4 = putstr_(_i18n_msg_get(ls_catd,NL_SETN,1807, "DESCRIPTION")), /* catgets  1807  */

            printf("%-13.13s %7.7s  %5.5s  %s\n",
		buf1, buf2, buf3, buf4);

	    FREEUP(buf1);
	    FREEUP(buf2);
	    FREEUP(buf3);
	    FREEUP(buf4);
	}

        for (i=0; i < lsInfo->nRes; i++) {
            if (!nameInList(namebufs, nnames, lsInfo->resTable[i].name))
                continue;
            if (!longFormat) {
               printf("%-13.13s %7.7s %5.5s   %s\n",
                   lsInfo->resTable[i].name,
                   valueTypeToStr(lsInfo->resTable[i].valueType),
                   orderTypeToStr(lsInfo->resTable[i].orderType),
                   lsInfo->resTable[i].des);
            } else
               print_long(&(lsInfo->resTable[i]));
        }

        for (i=0; i < nnames; i++)
            if (namebufs[i])
                printf(_i18n_msg_get(ls_catd,NL_SETN,1808, "%s: Resource name not found\n"),/* catgets  1808  */
		    namebufs[i]);

    }

    if (tFlag) {
        if (rFlag)
            putchar('\n');
        puts(_i18n_msg_get(ls_catd,NL_SETN,1809, "TYPE_NAME")); /* catgets  1809  */
        for (i=0;i<lsInfo->nTypes;i++)
            puts(lsInfo->hostTypes[i]);
    }

    if (mFlag) {
        if (rFlag || tFlag)
            putchar('\n');
        puts(_i18n_msg_get(ls_catd,NL_SETN,1810,
            "MODEL_NAME      CPU_FACTOR      ARCHITECTURE")); /* catgets  1810  */
        for (i = 0; i < lsInfo->nModels; ++i)
            if (mmFlag || lsInfo->modelRefs[i])
                printf("%-16s    %6.2f      %s\n", lsInfo->hostModels[i],
                    lsInfo->cpuFactor[i], lsInfo->hostArchs[i]);
    }

    _i18n_end ( ls_catd );

    exit(0);
}