🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.ms-windows.programmer.tools.mfc
Article #89

Re: spawnvp still does not work

#89
From: 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
Technical Details
Message-ID: <8ins805bng68tkovnm9k2m4l56abp85c17@4ax.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!border1.nntp.ash.giganews.com!border2.nntp.sjc.giganews.com!border1.nntp.sjc.giganews.com!nntp.giganews.com!local1.nntp.sjc.giganews.com!news.giganews.com.POSTED!not-for-mail
References: <7ecaee57.0404270215.69123ef8@posting.google.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1138df,849b6cbe3bfc9622
X-Google-Thread: 114592,a88c2c65285add14
X-Google-Thread: fa69e,afaff6b21cfb08a9
X-Google-Attributes: gid1138df,gid114592,gidfa69e,public
X-Google-ArrivalTime: 2004-04-27 06:29:43 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!border1.nntp.ash.giganews.com!border2.nntp.sjc.giganews.com!border1.nntp.sjc.giganews.com!nntp.giganews.com!local1.nntp.sjc.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Tue, 27 Apr 2004 08:29:43 -0500
From: Robert W Hand <rwhand@NOSPAMoperamail.com>
Newsgroups: comp.os.ms-windows.programmer.tools.mfc,alt.comp.lang.learn.c-c++,borland.public.cpp.borlandcpp
Subject: Re: spawnvp still does not work
Date: Tue, 27 Apr 2004 09:29:55 -0400
Message-ID: <8ins805bng68tkovnm9k2m4l56abp85c17@4ax.com>
References: <7ecaee57.0404270215.69123ef8@posting.google.com>
X-Newsreader: Forte Agent 2.0/32.652
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Lines: 109
X-Trace: sv3-5OoZr5OpFZucFOuxDW52wYaAOF57j0QLUgISFDCOHQ+LBBBrRI8PGwU69nXpx5acyvCUkMzudpTHlD9!8B3N+FC+6f9VuOSt4hYBizrtewgqc1Xq1Dic4s1LAY8J/WdGHjwz9FW++DLw3u9aCWsY
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.1