473,473 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Program that returns the minimum value using Fork

2 New Member
Hi: Here is my question...

Below program needs arguments from command line. How to modify the parent program to provide at least five integers inside of the program, not from command line and keep the program does the same as program.
Expand|Select|Wrap|Line Numbers
  1. #include <stdlib.h>
  2. int
  3. main< int argc, char * argv[]> {
  4.       int i=0, data[arg-1], min=0;
  5.       for  <i=1; i<argc; i++> /* convert strings to integar*/
  6.          data[i-1] = atoi<argv[i]>;
  7.       if <fork<> == 0> {
  8.          execlp<"./cat","cat","pg314.c", NULL>; /*run child program*/
  9.          perror<"exec failure">;
  10. exit<1>;
  11.       } else  {
  12.            min = data[0];  /*get minimum from the given values*/
  13.            for <i-1; i < argc-1; i++>
  14.                   if <data[i];
  15.              printf<'Min=%d\n", min>;
  16.         }
  17. }
  18.  
Please help me out. Thanks.
Sep 29 '07 #1
3 1609
weaknessforcats
9,208 Recognized Expert Moderator Expert
Why can't you just declare an array and intialize it with your values?
Sep 29 '07 #2
saif9171
2 New Member
Why can't you just declare an array and intialize it with your values?

Could you show me in the program like how to declare in array. It would be great if u write the program.

Thanks.
Sep 30 '07 #3
JosAH
11,448 Recognized Expert MVP
execlp<"./cat","cat","pg314.c", NULL>; /*run child program*/
I bet you found this somewhere on the net and simply copied and pasted it in
your program; that exec has nothing to do with finding a minimum value recursively
using fork(). Please repost your code in a decent way (correct the parentheses
and put your code in [ code ] ... [ /code ] tags (without the spaces).

kind regards,

Jos
Sep 30 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: tornado | last post by:
Hi all, I am pretty new to PHP. I was reading PHP manual and trying out the example from 2nd chapter (A simple Tutorial). When i try to print the variable as given in the example it returns...
1
by: Tony Johansson | last post by:
Hello experts! As this program is now it's works perfectly when running as a application or as an Applet. Now to my question if I just change this row "public class Converter extends Applet "...
9
by: santosh | last post by:
Hello all, I've put together a small program to count the number of characters and 'words' in a text file. The minimum length of a word, (in terms of no. of characters), as well as word...
4
by: cnoobie | last post by:
Problem 1 - Min, Mean, Max Write a program that reads in successive integer values from the user. The user will indicate termination of these values with the sentinel value 0 (zero). After the...
4
by: princessfrost | last post by:
Hi! I was wondering if someone could please help me with a hangman program that I have to do. I have some ideas, but really don't know what to do or where to start. My program needs to be:...
23
by: mike3 | last post by:
Hi. (posted to both newsgroups since I was not sure of which would be appropriate for this question or how specific to the given language it is. If one of them is inappropriate, just don't send...
2
Banfa
by: Banfa | last post by:
Posted by Banfa The previous tutorial discussed what programming is, what we are trying to achieve, the answer being a list of instructions constituting a valid program. Now we will discuss how...
4
by: zelmila19 | last post by:
Hi anyone, Could someone check this program for me, I've given it a go, it runs well but gives me 6 of this warning: warning C4244: 'initializing' : conversion from 'double' to 'int', possible...
4
by: Alexander Mahone | last post by:
Hello, apart from using fork() and exec*(), or system(), is there any other way to run the gperf command line program inside a C program? I need to generate at run-time a perfect hash function, and...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.