Board index » cppbuilder » spawnvp still does not work

spawnvp still does not work


2004-04-27 06:15:31 PM
cppbuilder76
I wrote that program but spawnvp dows not call the exe files
hello1,hello2!!!
#include <stdio.h>
#include <conio.h>
#include <process.h>
//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++);
}
 
 

Re:spawnvp still does not work

On 27 Apr 2004 03:15:31 -0700, XXXX@XXXXX.COM
( XXXX@XXXXX.COM ) wrote:
Quote
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.
Quote

#include <stdio.h>
#include <conio.h>
#include <process.h>
Non-standard headers, of course.
Quote

//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.
Quote
{
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.
Quote
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.
Quote
}

int user_selection()
{
int opt;
printf("\n Enter required option(1-3) : ");
Either flush or end with a new line.
Quote
scanf("%1d",&opt);
Wrong conversion specifier. ld is not for int. Use "%d".
Quote
return (opt);
}

void call_program(int opt,char *argv[])
{
void delay();
You are redeclaring delay. No need for that. Leave all the delays
out.
Quote
switch(opt)
{
case '1':
opt is an integer. You are comparing to character '1' that has a
different value than integer 1.
case 1:
Quote
spawnvp(0,"hello1.exe",argv);
delay();
break;
case '2':
case 2:
Quote
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