コード例 #1
0
ファイル: 1.c プロジェクト: harababurel/homework
void main_menu() {
    /* Method displays the user interface.
     */

    printf("(a) Generate all the prime numbers smaller than a given natural number n.\n");
    printf("(b) Given a vector of numbers, find the longest increasing contiguous subsequence.\n");

    char option;

    printf("Option: ");
    scanf("%c", &option);

    if(option == 'a') {
        printf("You chose option (a).\n\nn = ");        // prompt for n
        option_a();
    }
    else if(option == 'b') {
        printf("You chose option (b).\n\nn = ");        // prompt for n
        option_b();
    }
    else printf("Invalid option.\n");
}
コード例 #2
0
ファイル: jspell.c プロジェクト: gitpan/Lingua-Jspell
/**
 * @brief ...
 * @param argc
 * @param argv
 * @param lib
 */
int my_main(int argc, char *argv[], char lib)
{
    char *wchars = NULL;
    char *preftype = NULL;
    static char outbuf[BUFSIZ];
    int arglen, old_argc;
    char *cpd = NULL;
    char *Cmd = *argv;
    /* Pointer to name of $(LIBDIR)/dict */
    char *LibDict = NULL; 

    islib = lib;
    old_argc = argc;
    Trynum = 0;
    sprintf(hashname, "%s/%s", LIBDIR, DEFHASH);
    strcpy(signs, DEFAULT_SIGNS);

    argv++;
    argc--;
    while (argc && **argv == '-') {
		/*
		 * Trying to add a new flag?  Can't remember what's been used?
		 * Here's a handy guide:
		 *
		 * Used:
		 *        ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789
		 *        ^^^^       ^^^ ^  ^^ ^^
		 *        abcdefghijklmnopqrstuvwxyz
		 *        ^^^^^^*    ^^^*^  ^^*^^^*
		 */
		arglen = strlen(*argv);
		add_inc = 0;
	
		switch ((*argv)[1]) {
		case 'v':
		    option_v(Cmd, argc, argv, arglen);
		    break;
		case 'n':
		    preftype = option_n(Cmd, preftype, arglen);
		    break;
		case 't': /* TeX mode */
		    preftype = option_t(Cmd, preftype, arglen);
		    break;
		case 'T': /* Set preferred file type */
		    preftype = option_T(Cmd, argc, argv);
		    break;
		case 'A':
		    option_A(Cmd, arglen);
		    break;
		case 'a':
		    option_a(Cmd, arglen);
		    break;
		case 'D':
		    option_D(Cmd, arglen);
		    break;
		case 'J':
		    option_J(Cmd, arglen);
		    break;
		case 'e':
		    option_e(Cmd, arglen, argv);
		    break;
		case 'c':
		    option_c(Cmd, arglen, argv);
		    break;
		case 'b':
		    option_b(Cmd, arglen);
		    break;
		case 'x':
		    option_x(Cmd, arglen);
		    break;
		case 'f':
		    option_f(Cmd, argc, argv); 
		    break;
		case 'L':
		    option_L(Cmd, argc, argv);
		    break;
		case 'l':
		    option_l(Cmd, arglen);
		    break;
		case 'S':
		    option_S(Cmd, arglen);
		    break;
		case 'B':   /* -B: report missing blanks */
		    option_B(Cmd, arglen);
		    break;
		case 'C':   /* -C: compound words are acceptable */
		    option_C(Cmd, arglen);
		    break;
		case 'P':   /* -P: don't gen non-dict poss's */
		    option_P(Cmd, arglen);
		    break;
		case 'm':   /* -m: make all poss affix combos*/
		    option_m(Cmd, arglen);
		    break;
		case 'N':   /* -N:  suppress minimenu */
		    option_N(Cmd, arglen);
		    break;
		case 'M':
		    option_M(Cmd, arglen);
		    break;   /* -M:  force minimenu */
		case 'p':
		    option_p(LibDict, &cpd, Cmd, argc, argv);
		    break;
		case 'd':
		    option_d(LibDict, cpd, Cmd, argc, argv);
		    break;
		case 'V':    /* Display 8-bit characters as M-xxx */
		    option_V(Cmd, arglen);
		    break;
		case 'w':
		    wchars = (*argv)+2;
		    if (*wchars == '\0') {
				argv++; argc--;
				if (argc == 0)
				    usage(Cmd);
				wchars = *argv;
		    }
		    break;
		case 'W':
		    option_W(Cmd, argc, argv);
		    break;
		case 'o':
		    option_o(Cmd, argc, argv); 
		    break;
		case 'g':
		    option_g(Cmd, arglen);
		    break;
		case 'u':
		    option_u(Cmd, arglen);
		    break;
		case 'y':
		    option_y(Cmd, arglen);
		    break;
		case 'z':
		    option_z(Cmd, arglen);
		    break;
		default:
		    usage(Cmd);
		}  /* end switch */
	
		if (add_inc) {
		    argv++; argc--;
		}
		argv++; argc--;
    }

    if (!argc  &&  !lflag  &&  !aflag   &&  !eflag  &&  !dumpflag)
		usage(Cmd);

    verify_files(argc, argv);

    if (!oflag) strcpy(o_form, DEF_OUT);
	if (linit() < 0) exit(1); /* Force an error */

    det_prefstringchar(preftype);

    if (prefstringchar < 0)
		defdupchar = 0;
    else
		defdupchar = prefstringchar;

    if (missingspaceflag < 0)
		missingspaceflag = hashheader.defspaceflag;
    if (tryhardflag < 0)
		tryhardflag = hashheader.defhardflag;

    initckch(wchars);

    process_LibDict(LibDict, cpd);

    if (process_a_e_and_d_flags() == 0)
		return 0;

    if (!islib)
		setbuf(stdout, outbuf);

    /* process lflag (also used with the -c option) */
    if (lflag) {
		infile = stdin;
		outfile = stdout;
		if (!islib)
	    	checkfile();
		return 0;
    }

    /* n. of parameters advanced */
    return old_argc - argc; 
}