🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.os.ms-windows.programmer.tools.mfc
2 messages
2 total messages Started by hpy_awad Tue, 27 Apr 2004 10:15
spawnvp still does not work
#88
Author: hpy_awad
Date: Tue, 27 Apr 2004 10:15
66 lines
2076 bytes
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
#89
Author: Robert W Hand
Date: Tue, 27 Apr 2004 13:29
109 lines
3626 bytes
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 <stdio.h>
>#include <conio.h>
>#include <process.h>

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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads