C++ :: Sending Dynamic Allocated 2D Array Over Named Pipe Between 2 Executable
Oct 6, 2014
Im writing a scientific software where I like to sent a 2D array (5x4) over a named pipe from a server to a client. When im sending a static array (i.e., double res[5][4];), all goes fine and it works perfect, but when I allocate a dynamic array, it provides some nonsense numbers at the client side. I feel it might be caused because I point to a memory that cannot be shared through a pipe. Am I right and how can I pass the dynamic allocated array itself over the pipe.
//Server program
// Create a pipe to send/receive data
HANDLE pipe = CreateNamedPipe(
"\.pipemy_pipe", // name of the pipe
PIPE_ACCESS_DUPLEX, // 2-way pipe -- send and read
PIPE_TYPE_BYTE, // send data as a byte stream
1, // only allow 1 instance of this pipe
0, // no outbound buffer
[Code] .....
View 2 Replies
ADVERTISEMENT
Dec 9, 2014
I'm trying to write to a named pipe created by a service, as we all know the session 0 isolation implemented in vista and forward makes this task a bit complicated.
well at this point i managed to make almost all to work but my real problem comes when i try to write on the named pipe from my GUI application with no administrator rights
If i run the GUI application with admin rights it works 100% but, I don't need that application to require the user admin rights and for security reasons i rather to leave it without admin...
so i started my research and i found that there is a way to achieve this by calling CreateNamedPipe() with a low integrity security attributes...
well how to implement but i finally made it, the problem is that it gets worse than passing null security attributes, it works with admin rights with NULL security attributes, but when i pass the low integrity security attributes it gives "access denied" even when using admin rights, so i guess im passing the wrong security attributes but how to manually create the security descriptor string.
This is the code:
Service (session0) SERVER
Code:
DWORD WINAPI PipeThreadRSVS(void* pParameter){
LPTSTR _PIPE_NAME = "\.pipeRSVHPipeIn";
bool Break=false;
char Received_Buffer[BlockSize+16];
DWORD BytesRead = 0;
[Code] ....
View 2 Replies
View Related
Mar 25, 2013
I understand why you cant define them but why cant you name them. Or is it that you must always define them in order to name them?
Why do I have to always use a pointer???
Or is it that dynamically allocated variables on allocate space for a type to be stored and not really the variable itself so you must use a pointer???
View 1 Replies
View Related
May 22, 2013
I am just wondering if it is possible to send a project to someone via email - In a simple way, almost like you would install software from the internet, maybe a setup file, or something. The compiler I use "Dev C++" creates a .cpp file and an executable. Unfortunately, I cannot send that .exe file. How would you recommend sharing a program?
View 5 Replies
View Related
Feb 9, 2014
I'm trying to create a function that uses dynamic allocated arrays instead of vectors because I want to see how they work. Basically, this function asks the user to input how many people they are going to enter followed by their name; then, they enter how many of these people want to register for an ID followed by their phone #.
For example:
"How many customers will you like to enter? " 3 //user inputs 3
Bob Allen //user input
Ellen Michaels //user input
Jane Andrews //user input
[Code].....
View 1 Replies
View Related
Jul 10, 2013
So I wrote a program to turn a binary file's data into an unsigned character array for inclusion in an executable. It works just super.
I'm wondering how I can write a program that will perform this operation on every file in a directory and all it's sub-directories so that I can I can include everything I need all at ounce.
View 9 Replies
View Related
Jan 4, 2013
I'm writing a program in which I have to use a matrix to represent a file in code. because it's a file, the size of the matrix is undefined, and therefore the matrix has to be dynamic. I found out that my compiler doesn't like dynamic multidimensional arrays, so I was thinking of this matrix as a dynamic (monodimensional) array of other dynamic (monodimensional) arrays. My program (and thus this example) uses unsigned chars.
unsigned char variable=something;
unsigned char**matrix=new unsigned char*[lenghtOfMainArray];
for(int rowNumber=0;rowNumber<lenghtOfArray;rowNumber++)
{
[Code].....
View 2 Replies
View Related
Jan 18, 2014
I'm trying extremely hard to understand pointers and I have the basic concept down.. I feel as though my knowledge of dynamically allocated pointers and pointers in general is not enough to understand the logic behind what I'm trying to do. The problem is that the donations array must be able to accept any number of donations. I've made it do just that, but there is also an array of pointers which must each point to the same element in the donations array. The program works if I assign int *arrPtr[100] for example, but it does not work if I try to dynamically allocate it to accept the same number of elements for donations entered by the user. Here it's the snippet
#include <iostream>
using namespace std;
//Function Prototypes
[Code]....
View 2 Replies
View Related
Oct 4, 2014
I have changed my const global int NUMLABS to a non constant variable so that the user can decide how many labs to input. I adjusted the parameters of each function to add NUMLABS becuase the variable is no longer constant. But now main() returns 0 right after the user chooses how many stations to put in each lab. I am having difficulty understanding these dynamically allocated arrays.
/*********************************************************************
Lab4.cpp
This program uses dynamic arrays to store login information for four labs. Each of the four labs is referenced by the labs[] array which is indexed from 0-3. A pointer in the labs[] array then references a dynamic array that is of size for however many computers are in that lab.
Written by: Luca Del Signore
Last modified on: October 3rd
Known bugs: N/A
*********************************************************************/
#include <iostream>
#include <cstdlib>
using namespace std;
[Code]....
View 1 Replies
View Related
Jun 22, 2013
Suppose I wished to initialize a dynamically allocated array of integers to zero. Would I do better to use calloc() or malloc + iterate over all entries setting each to zero? Which one is regarded as a better approach?
View 12 Replies
View Related
Jul 15, 2013
Code:
void readFile(struct course *d, char* filename){
FILE* fp;
char buffer[100];
int i = 0, array_size = 100;
struct course *temp;
[code]....
I will be using this to read data from a file. I start with an array of 100 structures being passed to the readfile function. Once it reads 100 lines (i == array_size), I want to double the array size until I have finished reading the file.
Two questions.
1)My initial thought was that I needed to keep track of the lines read with my variable, i. However, is there a better way?
2)My program is crashing right now at the call to double_array_size function. What is wrong with my code? Never dealt with dynamically allocated array of structures and functions.
I read online that I should change my code in the following manner.
Code:
void readFile(struct course *d, char* filename) {
FILE* fp;
char buffer[100];
int i = 0, array_size = 100;
struct course *temp;
[code]....
I can paste the "error messages" if you like, but it is a page full of stuff I have never seen. glibc detected, Backtrace, Memory Map, and a bunch of numbers and hexadecimal stuff like addresses.
View 12 Replies
View Related
May 4, 2013
I'm trying to read in a file and store it in an array that is dynamically allocated of a struct (which I'm not sure how to do), then parse each line using strtok() from string.h. The idea is to separate the lines by date, subject, time, etc.
Since the array is a dynamically allocated of typdef struct, it's sorted by the date of each struct, with an intial size of 25. But whenever the array needs to be resized, it should be doubled.
View 1 Replies
View Related
Oct 5, 2014
this is my function for allocating memory in 2D array
Code:
#include <stdio.h>
#include <stdlib.h>
int allocate_array(int **array, int *row, int *column){
int i;
}
[code]....
end of allocate_array function and this is my function for asking for the values to be stored in array
Code:
int input_array(int **array, int row, int column){
int i, j;
//ask for the values to be stored in the 2D array
for( i = 0; i < row; i++ ){
for( j = 0; j < column; j++ ){
}
[code]....
why I'm having error here in my input_array() function
Code: scanf("%d", &array[i][j]);
View 2 Replies
View Related
Dec 13, 2013
I would like to know if this code is correct.
#include <iostream>
#include <string>
int say_one(const std::string &s) {
std::clog << s << ": One!
[Code] .....
View 7 Replies
View Related
Sep 18, 2014
How can I return a dynamically allocated 2d array from a function? Do I use like this:
int main(){
char **array;
array=func();
} char ** func(){
char** ptr=new char[5]; //five words
ptr[0]=new char[size of word1];
*ptr[0]=word1
........
return ptr;
}
View 8 Replies
View Related
Jan 12, 2013
Just trying to fill a dynamically allocated array with values then I want to print out the values using pointer method:
#include <iostream>
using namespace std;
long * extend_arr(long int arr[], long int length, long int val) {
long * array2 = new long [length + 1];
for (int J = 0; J < length; ++J)
array2[J] = arr[J];
[Code] ....
When this runs, I get an array with random numbers in it. For example, just trying to print the first value in *Block gives me random numbers each time. What is wrong with this as to why it is not holding the right values?
The extend_arr works perfectly fine, because when I try to access the values in the array using indexes (arr[0], arr[1], etc) it shows the right output, but using pointers does not. How can I make it work?
Output:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 134561 23 29 640 112
As you can see, the primes end at 97 but it just keeps printing more
It now prints the correct values in the function if I set the last value in the array to 0. arr[length] = 0;
Now if I wanted to print the values in the array within main, why is that not working?
Nvm, I just changed the void function to return a pointer to an array.
View 2 Replies
View Related
Jul 27, 2014
This a very simple program I created because I dont understand how do this. My goal is to be able to use the pointer *s5 throughout the program. For example I would to like to call other functions and pass that pointer through the function. I understand the dynamic allocation and pointers for the most part but Im confused here because the "new char[20]" variable will die after the function and I dont want it to.
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
void testArray ( char *s5 );
int main ( int argc, char *argv[] )
[Code] .....
Also does strlen count the null terminator?
View 1 Replies
View Related
Feb 13, 2013
In a program I'm working on now, i need a milti-dimensional array. To save space, I used dynamically allocated array by using pointers, something like this-
int *arr;
arr=new int[col*row];
And now i need to pass this array in a function. What are the parameters in the function declaration statement and at the function call statement?
View 4 Replies
View Related
Jun 29, 2014
I'm trying to write a function that returns a pointer to a dynamically allocated array. Here's my code:
#include <iostream>
using namespace std;
void IndexArray(int, int);
int main(){
int *arr, n;
[Code] ....
When I try running the program, I get the error
"Unable to start program 'D:C++FilesdynamicArraySolReleasedynamicArray.exe'. The system cannot find the file specified."
I'm honestly not sure if the issue is my program, or something with C++. At the moment, I cannot debug any of my programs or else I get the same exact error. I basically need to release everything without debugging it. I last used C++ about a year ago and I'm finally back in school, and so trying to get back into it. I use Microsoft Visual C++ 2010.
View 14 Replies
View Related
Dec 4, 2014
My output becomes nonsense when I changed i value. how can I make tyy[i] value depends both i(depends on cins value) and j(depends on saft.size())
for ( int i = 0 ; i < cins ; i++ ){
for (int j=1 ; j < saft.size() ; j++) {
if (ustk[i] > saft[j] && saft[j-1] > ustk[i]){
tyy[j] = ((ustk[i] - saft[j])*yy[i]);
[code] ....
View 6 Replies
View Related
Jul 8, 2014
When declaring char array[10], memory is allocated for 10 1-bit memory locations. Is extra memory allocated for storing the address of array[0]? In expressions, is array equivalent to a pointer constant or is it an identifier for a memory cell containing the address of array[0]? In other words, is array a variable or an alias for &array[0]?
View 6 Replies
View Related
Feb 25, 2013
I am having some trouble on understanding how to create a dynamically allocated array and then inputting some information in to it from a text file.
Example text file:
John Doe saving 135246978 300 0
View 1 Replies
View Related
Jul 26, 2012
Project compile successfully but console turn off with "Windows " with error doesn't print or get anything
Code:
#ifndef Point_HPP // anti multiply including gates
#define Point_HPP
#include <string>
#include <iostream>
#include <sstream>
#include <cmath>
[Code] .....
View 2 Replies
View Related
Mar 3, 2014
I am trying to store each value of a column from a text file into an dynamically allocated array, which needs to be globally declared for further usage in the program.The input textfile contains the following:
34932 13854 13854 2012-01-07
172098 49418 53269 2012-01-07
I have written the following code:
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
}
[code]....
The commented printf line gives the entire values of the column, which proves that the file is correctly being read.But on compiling this program I get both compiler warnings and finally segmentation fault.
View 5 Replies
View Related
Feb 26, 2013
Having some frustrating issues trying to free memory from a dynamically allocated array of pointers to linked lists. I think the problem is in how I initialize the pointers to NULL. Is there a more elegant way to have the program recognize that the list is empty so it knows to create a head node for the linked list in the function 'add_end_stub_to_array'?
I ran the code through Valgrind and it says that memory is definitely lost from this array.
This is the structure definition.
Code: struct stub_edge {
int loc_id;
int anim_type;
int mkt;
struct stub_edge *next_node;
};
Here is the code snippet from main allocating and deallocating memory to the array.
Code:
struct stub_edge **stub_list = (struct stub_edge **)malloc( sizeof(struct stub_edge *) * 12);
for (i = 0; i < 12; i++)
{
stub_list[i] = (struct stub_edge *)malloc(sizeof(struct stub_edge));
stub_list[i] = NULL;
}
stub_list = add_end_stub_to_array(end_stubs, stub_list);
destroy_end_stub_array(stub_list);
Here the function for adding nodes to the lists by reading through a dynamically allocated 2D array. (The end_stubs array is ordered by month and each linked list represents events occuring within the month).
Code:
struct stub_edge **add_end_stub_to_array(int **end_stubs, struct stub_edge **list)
{
long int i = 0;
int mon = 0;
struct stub_edge *current_node1;
struct stub_edge *new_node1;
int break1 = 0;
while(i < num_edges && break1 == 0 && mon < 12)
[Code]...
Here is the function for freeing memory from the list.
Code:
void destroy_end_stub_array(struct stub_edge **list)
{
if(list != NULL)
{
int mon = 0;
struct stub_edge *current_node1;
struct stub_edge *new_node1;
for(mon = 0; mon < 12; mon++)
[Code]...
View 1 Replies
View Related
Nov 9, 2012
My 'c' program reads each line of a .txt file, makes a few changes and then outputs the line of text (which are names). I want the contents to be sorted and did not want to bother writing my own sort. The program runs in a command prompt from inside a batch file for example:
sort | makelist.exe BluRay1.txt > sorted.txt
sort | makelist.exe Dvd1.txt >> sorted.txt
..etc..
I have to supply a ctrl-z manually to close the piping. I tried the following which did not work.
buffer[0] = 26;
printf("%c",buffer[0]);
//printf("^(z)");
fclose(stdout);
fclose(stdin);
I never got the above to work so I am avoiding piping and just do a redirect instead.
makelist.exe dvd1.txt > unsorted.txt
makelist.exe dvd2.txt >> unsorted.txt
sort < unsorted.txt > sorted.txt
..etc.
Just wondering if I could have gotten the ctrl-z thru the pipe using "C".
View 2 Replies
View Related