C++ :: Writing To 2D Array Of Pipes In Child Process

Apr 15, 2014

I am writing a program that is supposed to open a directory as a command line argument, read that directory, open each file and count a number of occurrences of a certain character, taken from the user as cin, fork the parent process to create a child process for each file. a pipe is created for communication with the parent and a 2 dimensional array of pipes is needed for communication with each child process (each file), one for the pipe number and the other is the read/write descriptor(0 or 1). My program is looping through all the files ok, but it seems it isn't writing the "char a" to the pipe correctly. f

For every child, do_child_stuff() is called, and it reads the file name, opens it, counts the # of occurrences and returns that count to the parent to hold a total for all the files. normally to write to a pipe, it should be write(pipe_name[1], &a, sizeof(a)) but I don't know how to do this with an array of pipes. i try to write to it by doing write(child_pipe[pc][1], &a...) pc is the array position for that pipe and it gets incremented after reading each file.

struct dirent *d;
struct stat sb;
int adult_pipe[2];
int child_pipes[1000][2];

[Code]....

View 5 Replies


ADVERTISEMENT

C :: Pipes Between Child Processes

May 5, 2014

I wrote a C program that is supposed to create a certain number of child processes, each child process having to change 1 letter from a string. The string and the number of child processes are read from the keyboard. I want to do it using pipes.

It should work like this: The parent changes one letter, then the first child takes the string modified by the parent and changes one more letter. The second child takes the string modified by the first one (2 letters are already changed) and changes one more and so on. I am new to C and am not quite sure how it all works, especially pipes. Also can the children be linked between them through the pipe, or can they only be linked to the parent and it has to be something like: first child changes a letter, gives the string back to the parent and then the second child reads from there, modifies letter and gives back.

If it's like that, is there any way to make sure that this doesn't happen: Apples becomes AppleD and then AppleX and then AppleQ? For example:

Code:
Input: Apples
Output: Applex Appldx Aqpldx My problem is: I don't get any output from the children.

Here's my code:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<sys/types.h>
#include<unistd.h>
#include <sys/wait.h>

[Code] .....

View 2 Replies View Related

C/C++ :: Two Way Communication Between Child And Parent Processes (pipes)

Mar 19, 2014

I want parent and child processes to communicate in C linux using pipes. I have created two file descriptors. one for parent to child i.e. readpipe and other writepipe for viceversa. But I am getting null as output for ch and ch1 strings in my code below.

#include <stdio.h>
#include<stdlib.h>
#include
#include<unistd.h>
int main(){
pid_t pid;

[Code] .....

View 1 Replies View Related

C++ :: Executing A Child Process?

Oct 11, 2012

how I can run this as a separate process from the parent program, like a child process,

and return the result back to the parent program.

this script is as follows.

if file "/Stuff/s" exists then continue to run, if file "/Stuff/t" exists, then print "started" if file "/Stuff/t" does not exists, then print "stopped"

if file "/Stuff/s" does not exist then print "quit" and then quit.

Code:
void controlxmmscheck( ) {
if( access( "/Stuff/s", F_OK ) != -1 ) {
xmmscheck
} else {

[Code]....

View 1 Replies View Related

C++ :: Give Output To Child Process

Apr 15, 2012

I'm trying to build a basic shell for Unix. This is the code I use to create a new process:

Code:
pid = fork();
if (pid == 0) {
setpgrp();
complexCommand(argv, isComplex);

[code] .....

Where complexCommand is a function that handles the command (uses execvp after generating the correct string out of argv). My problem is that after if while in the shell I use a program that needs to print to the screen and handle input, it doesn't work as expected. To test this, I built this small program:

Code:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main() {
int x1, x2;

[code] ....

And when I use the shell I built to run it, the output is only "Enter 2 numbers" for one time. It doesn't print the result, or anything else. Is there anything I need to do in the parent process (my shell in this case) to give the child the output?

View 2 Replies View Related

C :: Create 9 Child Processes And Eventually Write From Each Process To Another?

Nov 18, 2013

I want to create 9 child processes and eventually write from each process to another. How can I specifically create 9 child processes and leave them running? Right now, I am using a loop from i=0 to i=8 and running fork() within that loop, but each child process also runs the loop, which spawns dozens (maybe hundreds?) of processes. I specifically only want to create nine of them. How can I do this?

Code:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>

[Code].....

View 7 Replies View Related

C :: Edge Detection Done Using Processes And Pipes

Nov 30, 2014

I don't think my processes are being created the way I want. I'm trying to create a fan of process (i.e. one parent with multiple children).

I want the parent to put together the final output image, and the children are supposed to do the edge detection on various regions of the image. Here is what I have:

Code:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "iplib2New.c"
#define FILTER_SIZE 3
//Function prototypes

[Code] ......

View 10 Replies View Related

C :: Parsing Char Array To Array Of Struct To Process Packets

May 28, 2013

I wrote this simplified version of a program i am writing that parses data in UDP packets. In the process of doing so i pretty much answered all my questions and fix all the problems i was having.

decodeSystemMap function will be in loop, and will proccess packets that have mostly the same data, only a few items will be added or changed or deleted.

whats the best way to check if there are any new, deleted, or removed items in the packet and only modify those?
Is there anything unsafe / dangrous about the way the code is now?

Code:
/* * File: main.c
* Author: david
*
* Created on May 23, 2013, 11:57 AM
*/

#include <stdio.h>
#include <stdlib.h>

[Code] ....

View 4 Replies View Related

C++ :: Using Loop To Process Array Of Characters Starting From Beginning Of Array?

May 3, 2014

Assume you want to use a loop to process an array of characters starting from the beginning of the array. You want the loop to stop when you read the null terminator character from the array. Fill in the loop test condition that will make this work correctly.

index = 0;
ch = array[index];
while ( _____________________________)
{
// process the character
index++;
ch = array[index];
}

View 1 Replies View Related

C/C++ :: Writing Array To Binary File

Mar 10, 2014

So I'm trying to write an array of integers to a binary file. He's my code:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

[Code].....

I know that it is an array of characters right now, and I will be using the reinterpret_cast when I finish my program. Anyways, when I run the executable, it only writes 1234 to the file. My assumption was that the sizeof() was not being set properly, but even manipulating that won't fix it.

View 6 Replies View Related

C :: Redirecting Multiple Pipes With Multiple Children

Mar 21, 2014

I've been working on a function that works like a pipeline of a shell but receives a directory, go over it an search for every file to send it to a filter, something like this in bash "cat dir/* | cmd_1 | cmd_2 | ... | cmd_N", The only problem i have with the code is the redirection of the pipe descriptors.

Code:

int main(int argc, char* argv[]){
char** cmd;
int Number_cmd;
cmd = &(argv[2]); /*list of cmds*/
Number_cmd = argc-2; /*number of cmds*/
}

[code]....

The code is seems to work fine except when i run it with more than one command in example ("./filter DIR wc rev") in this case it returns

wc: standard input: Bad file descriptor
wc: -: Bad file descriptor
0 0 0

View 2 Replies View Related

C++ :: Writing Strings Into Array Index Within A Function?

Apr 11, 2014

I'm trying to make a calendar and I don't know how to cin strings into an array's index inside a function.

This is my current program.

Code:
#include<iostream>
#include<string>
using namespace std;
void viewMonth (string month[], int num);
void dayNote (string month[]);
int main()

[Code].....

View 1 Replies View Related

C/C++ :: Writing Strings Into Array Index Using Function

Apr 11, 2014

I'm trying to make a calendar and I don't know how to cin strings into an array's index inside a function.

This is my current program.

#include<iostream>
#include<string>
using namespace std;

void viewMonth (string month[], int num);
void dayNote (string month[]);

[Code] .....

How do I make void dayNote function work so I can cin a string into the desired array index?

View 3 Replies View Related

C++ :: Writing In Binary Format Array Of Unsigned Int Values

Aug 5, 2013

I am trying to write down in binary format an array of unsigned int values but i get the following compilation error :

: In function ‘int CIndex(std::fstream&, std::fstream&, std::fstream&, std::fstream&)’:
./src/IndexBuilder/index.cpp:23:26: error: no matching function for call to ‘std::basic_fstream<char>::write(int*, long unsigned int)’
./src/IndexBuilder/index.cpp:23:26: note: candidate is:
/usr/include/c++/4.6/bits/ostream.tcc:184:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::write(const _CharT*, std::streamsize) [with _CharT = char, _Traits = std::char_traits<char>, std::streamsize = long int]

This is the part the is not working:

Code:
// uia is : unsigned int * uia;
// then I have allocated the space for it
// load it with unsigned int's
// k is the number of variables in my array

o.write(uia,sizeof(unsigned int)*k); But thsi should be so simple and strait forward.... in c i do it as :

Code:
fwrite(uia, sizeof(unsigned int), k , fp); but since i would need to convert fstream to FILE* i decided to do it c++ way.

and this is how i opened the file :

Code:
o.open (fileName.c_str(),std::ios::out|std::ios::binary);

View 5 Replies View Related

C++ :: Writing Integer Array To File In Binary Form And Reading It

May 30, 2013

Both arrays arr and pointers are the same size. I am having problems reading pointers from file into a new int array.

FILE* ky_pt=fopen("stashedclient","ab");
write(fileno(ky_pt), pointers, sizeof(pointers) );
pointerindex=lseek(fileno(ky_pt), 0, SEEK_CUR );
printf("pointerindex after writing array %d

[Code] .......

View 2 Replies View Related

C :: Writing Structure Array Bytewise To Binary File And Read It Back

Aug 21, 2014

I would like to write a complete structure array to a file and read it back, recovering all the data. I have tried the following:

Code:

#include <stdio.h>
#include <string.h>
#define NUM 256
const char *fname="binary.bin";
typedef struct foo_s {
int intA;
int intB;
char string[20];

[Code]...

//---------------------------------------------------- but the mac field is reading back some random value repeatedly. Why is that? And how do I fix this?

View 8 Replies View Related

Visual C++ :: Writing A Function That Sort Elements Of Array In Numerical Order?

Oct 17, 2014

I have to write a function called sortMe that sorts the elements of an array in numerical order from highest to lowest values (descending order) or vice versa (ascending order).

The assignment asks to: NOT re-arrange elements in the array; instead, it uses a second array, an array of indexes for the elements in the original array and then sortMe sorts the second array based on the values in the original array. A sorted version of the original array can then be produced with these sorted indexes.

Header of the function sortMe must be as shown below:

void sortMe(int array[],int sortedIndexes [], int size, char mode)

When mode is 'a', the function sorts the array in the ascending order, and when mode is 'd', the function sorts it in the descending order.

Declare and initialize the array array.

Declare the array sortedIndexes but do not initialize it. You are going to play with the array sortedIndexes in the function sortMe.

EXAMPLE:

int array[5]={3, 5,-1,10,0};
int sortedIndexes[5];
sortMe(array,sortedIndexes, 5, 'a');

After the function call, the elements of the array sortedIndexes should be: 2,4,0,1,3.

notice that the function does not e-arrange the elements in the array.

Code:
#include <iostream>
using namespace std;
void sortMe(int[], int, char);
void main() {
int arr[6] = { 14, -5, 5, 0, 22, -99 };

[code]...

how to use the other array.

View 5 Replies View Related

C# :: How To Add A Child Row To A Table

Aug 1, 2014

I have a table in which data is populated via an element. However some elements can have a parent element

The client now wants all the children and parent elements to be next to each other row wise.

How can i add the child rows under the parent rows?

parents
foreach (var inspection in elemInspections) {
var date = db.INSPEVNT.Find(db.INSPEVNT.INSPKEY == inspection.INSPKEY && db.INSPEVNT.BRKEY == m_sBrKey);
var paircode = db.PON_ELEM_DEFS.Find(db.PON_ELEM_DEFS.ELEM_KEY == inspection.ELEM_KEY);

[Code] .....

how can i make it so the children go under the parent rows?

View 2 Replies View Related

C :: Writing Array Into File And Reading Array From File

Apr 20, 2014

i've been trying to write array into file and read them into the same program again, but the output is all wrong.

Code:

#include<stdio.h>
int main()
{
FILE *fp;
char name[3][7];
int x;
}

[code]....

View 1 Replies View Related

C++ :: Size Of Object Of Class Child?

Feb 5, 2014

hiclass Parent {
};
class Child : virtual public Parent {
};

What is the size of object of Class Child in following case?

View 17 Replies View Related

C# :: How To Allow TreeView To Have Child Nodes Of Different UI Types

Jul 14, 2014

Right now I'm working on a TreeView for which I would like to add a TextBlock and a ComboBox as child nodes of a Parent TextBlock node. This would look something like this:

My TreeView is implemented using an MVVM style, and utilizes a HierarchicalDataTemplate. I have had no problems with adding TextBlock nodes and TextBlock children, but the confusion seems to arise when adding child nodes of different UI types.

I have tried implementing a stackPanel, like so:

<HierarchicalDataTemplate DataType="{x:Type Data:Node}" ItemsSource="{Binding Teams}">
<StackPanel>
<TextBlock Text="{Binding IndividualProperty}" />
<ComboBox ItemsSource="{Binding CollectionProperty}" />
</StackPanel>
</HierarchicalDataTemplate>

But then I end up with each node looking like this. It's like each node comes with one TextBlock and a ComboBox (Note: The comboBox is not the child, it and the TextBlock are one node):

How do I allow my treeView to have child nodes of different UI types? I am thinking that my solution has to do with my Hierarchical Data Template.

View 4 Replies View Related

C/C++ :: How To Create Single Instance Of Child Exe

Nov 13, 2013

I have an MFC application(.exe) in which i am creating an pointer object to CComQIptr<chemst::IChems>myinfo and after this i have using cocreate instance i had created the object launching that object, so Where i am using that CComQIptr object.

I have been creating instance to that COM exe (child exe) and at the end of the function i am releasing that object (myinfo->release).i want to create single instance for it and i want to use them in different .cpp files and finally i want to kill the child exe. Even though i release the object it is still alive.(Visualising in Task manager whether the exe is still alive or not).

View 1 Replies View Related

C++ :: Deleting Node (With Two Child) In Trees

Sep 20, 2013

I have Problems with deleting node in trees!my first problem is I don't understand the algorithm of deleting a node with two child! I write some kind of code that delete a node with two child but I think (maybe I should say I am sure ) that it has runtime or logical errors or something like that!

My second problem is my code doesn't work if my node is root of tree!because I don't know if it is root what should be the parentPtr in my code! I set parentPtr to NULL in this situation but I know it is wrong!

Here is my Code :

#include <iostream>
#include "TreeNode.h"
using namespace std;
template<typename NODETYPE> class Tree {
public:
Tree();
void insertNode(const NODETYPE &);

[Code] .....

View 3 Replies View Related

C++ :: Function Overloading In Child Class?

Jan 17, 2014

I am facing some problems while overloading base class functoin in child class. I have 2 programs as listed below.

Program 1 :

#include <iostream>
using namespace std;
class base
{

[Code].....

Compilation Errors:

child_overload.cpp: In function "int main()":
child_overload.cpp:27: error: no matching function for call to "child::func(const char [16])"
child_overload.cpp:17: note: candidates are: void child::func(double)

I thought as base class members are also as part of child class through "public" access specifier, it should access base class function, when funct() is called with a string. if I use "using base::func" in child, it works fine. But why I need that when base class memebers are part of child class?

View 2 Replies View Related

Visual C++ :: How To Create MDI Child With Borders

Jan 7, 2013

How can I create MS Word 'print layout' like interface. The attached picture says it all. Basically I want a shaded area around my document just like word so it gives a feel of the 'page'.

I was hoping I can override some function somewhere and along that lines tried playing around with below but that didn't work.

Code:
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) {
if( !CFrameWndEx::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.cx = 250; // just playing around with size
cs.cy = 250;
return TRUE;
}

How can I do that?

View 6 Replies View Related

Visual C++ :: Child Window On Top Of Control

Nov 30, 2014

I have a child window above an edit control.

When the position of the control in the parent in the child on top of it is clicked the control gets topmost. Is there any way to prevent this?

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved