spawnvp still does not work - Programmer

This is a discussion on spawnvp still does not work - Programmer ; I wrote that program but spawnvp dows not call the exe files hello1,hello2!!! #include #include #include //Tv Rental system menu version 1 int user_selection(); void display_menu(); void call_program(int option,char *argv[]); int main(int ,char *argv[]) { int option; do { display_menu(); ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: spawnvp still does not work

  1. spawnvp still does not work

    I wrote that program but spawnvp dows not call the exe files
    hello1,hello2!!!

    #include
    #include
    #include

    //Tv Rental system menu version 1
    int user_selection();
    void display_menu();
    void call_program(int option,char *argv[]);
    int main(int ,char *argv[])
    {
    int option;
    do
    {
    display_menu();
    option=user_selection();
    if (option!=7) //Exit
    call_program(option,argv);
    }
    while (option!=7);
    return 0;
    }


    void display_menu()
    {
    clrscr();
    printf("1 hello1");
    printf("\n2 hello2");
    printf("\n3 exit");
    }

    int user_selection()
    {
    int opt;
    printf("\n Enter required option(1-3) : ");
    scanf("%1d",&opt);
    return (opt);
    }

    void call_program(int opt,char *argv[])
    {
    void delay();
    switch(opt)
    {
    case '1':
    spawnvp(0,"hello1.exe",argv);
    delay();
    break;
    case '2':
    spawnvp(0,"hello2.exe",argv);
    delay();
    break;
    default:
    printf("\n incoreect input");
    delay();
    exit(0);
    }
    }
    void delay()
    {
    int i;
    for (i=0;i<20000;i++);
    }

  2. Re: spawnvp still does not work

    On 27 Apr 2004 03:15:31 -0700, ehab_aziz2001@yahoo.com
    (hpy_awad@yahoo.com) wrote:

    >I wrote that program but spawnvp dows not call the exe files
    >hello1,hello2!!!


    spawnvp works fine on my Windows XP system. It is your C code that
    fails. Please see below. I am answering from acllc-c++ that does
    standard C and C++. spawn and several other parts of your program are
    extensions and not part of standard C.

    >
    >#include
    >#include
    >#include


    Non-standard headers, of course.

    >
    >//Tv Rental system menu version 1
    > int user_selection();
    > void display_menu();
    > void call_program(int option,char *argv[]);
    >int main(int ,char *argv[])


    You need a variable name for the first parameter.

    >{
    > int option;
    > do
    > {
    > display_menu();
    > option=user_selection();
    > if (option!=7) //Exit
    > call_program(option,argv);
    > }
    > while (option!=7);


    Why make option 3 exit, but then use option 7 here? Please be
    consistent.

    > return 0;
    > }
    >
    >
    > void display_menu()
    > {
    > clrscr();
    > printf("1 hello1");
    > printf("\n2 hello2");
    > printf("\n3 exit");


    You should print lines with printf. End the last printf with a new
    line character.

    > }
    >
    > int user_selection()
    > {
    > int opt;
    > printf("\n Enter required option(1-3) : ");


    Either flush or end with a new line.

    > scanf("%1d",&opt);


    Wrong conversion specifier. ld is not for int. Use "%d".

    > return (opt);
    > }
    >
    > void call_program(int opt,char *argv[])
    > {
    > void delay();


    You are redeclaring delay. No need for that. Leave all the delays
    out.

    > switch(opt)
    > {
    > case '1':


    opt is an integer. You are comparing to character '1' that has a
    different value than integer 1.

    case 1:

    > spawnvp(0,"hello1.exe",argv);
    > delay();
    > break;
    > case '2':


    case 2:

    > spawnvp(0,"hello2.exe",argv);
    > delay();
    > break;
    > default:
    > printf("\n incoreect input");


    Please spell user inteface messages properly.


    With those changes, the program compiled and ran as expected.


    Best wishes,

    Bob

+ Reply to Thread