Passing struct through unix pipe -solved


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Passing struct through unix pipe -solved
# 1  
Old 03-06-2010
Passing struct through unix pipe -solved

EDIT: Nevermind, called a friend who is good at this stuff and he figured it out Smilie

Hi all,

So I'm trying to teach myself to write programs for unix in c. I am currently creating a program, and I need to pass a struct through a pipe, but I can't figure out how.

The struct I want to pass has two types in it, one enum and one union of two other structs. These two other structs each contain an int and a char variablename[256] array.

gcc won't let me just pass the struct using write(pipefd[1], struct, size_of_struct) since the struct is not a char buffer. So that's my question...how does one go about passing a struct?

Thanks!

EDIT: Nevermind, called a friend who is good at this stuff and he figured it out Smilie

Last edited by twnsfn34; 03-06-2010 at 10:51 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help on passing an input variable to the voronota program (after third pipe)

Dear UNIX forum members, I am using macbook pro 13 (2015 edition) with MAC OS Mojave and am trying to write the shell script where when it is run through terminal it asks for an input (in the code below an input variable is domains) and then that input becomes capital letter or letters which... (3 Replies)
Discussion started by: Aurimas
3 Replies

2. UNIX for Dummies Questions & Answers

[Solved] How to swap PIPE seperator delimiter?

I have file like below 1|4|OR|OLAP|INT|INT||CONSTANT|2012/08/07|9999/12/31|0|0|0|0|PRL|-358.1684563||||||||||36522|55791|LNR| 2|4|OR|OLAP|CLR|CLR||CONSTANT|2012/09/07|9999/12/31|0|0|0|0|PRL|-358.1684563||||||||||36522|57891|REGS|... (2 Replies)
Discussion started by: gkskumar
2 Replies

3. Shell Programming and Scripting

[SOLVED] nawk FS using pipe read variables from file

I have a file data_1.out which contains: 1|abc mail|mail subject|mail body 2|def mail|mail subject|def mail body I am trying to read the variables from data_1.out and use them to print to 2 different files based on the id (first_column) The problem is I am not able to read the file... (8 Replies)
Discussion started by: sol_nov
8 Replies

4. Programming

[solved]help passing array of structs to function in c

this is my code to try and prinnt out a deck of cards. the print function worked when used inside main without being a function but now i cant get it to work as a function probably since i dont know how to pass a struct array in c. I gave it a shot but i keep getting an assortment of errors. The... (0 Replies)
Discussion started by: bjhum33
0 Replies

5. Programming

Storing C++-struct in file - problem when adding new item in struct

Hi, I have received an application that stores some properties in a file. The existing struct looks like this: struct TData { UINT uSizeIncludingStrings; // copy of Telnet data struct UINT uSize; // basic properties: TCHAR szHost; //defined in Sshconfig UINT iPortNr; TCHAR... (2 Replies)
Discussion started by: Powerponken
2 Replies

6. Programming

Passing an instance of struct to functions in other src files

I am trying to work out the best syntax for a relatively simple operation. The goal is to declare an instance of a struct and pass it around to be populated and have the data manipulated. There is an extra wrinkle in that the functions are in different src files. The main is simple, #include... (5 Replies)
Discussion started by: LMHmedchem
5 Replies

7. Homework & Coursework Questions

Passing pointers to struct

Hi, i'm trying to copy a struct into a binary file using the unix instruction write, so i declare and fill the struct "superbloque" in one function "initSB" and then i pass the pointer to another function called bwrite (for block write) which calls write. The problem is that i call the function... (2 Replies)
Discussion started by: ignatius3
2 Replies

8. UNIX for Dummies Questions & Answers

How to access a struct within a struct?

Can someone tell me how to do this? Just a thought that entered my mind when learning about structs. First thought was: struct one { struct two; } struct two { three; } one->two->three would this be how you would access "three"? (1 Reply)
Discussion started by: unbelievable21
1 Replies

9. UNIX for Dummies Questions & Answers

Standard error output to Pipe input - solved

Hi, I want to check a particular word is in standard error output or not. Can I acheive it in single command? For example, Delete file_name 2>error.log cat error.log Output: XXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX Successfully deleted XXXXXXXXXXXXXXXXX where delete is... (2 Replies)
Discussion started by: poova
2 Replies

10. UNIX for Advanced & Expert Users

Passing socket struct between kernel threads - module programming

I write kernel module with kernel threads using linux/kthread.h on 2.6.* kernel I tried to passing data between two kernel threads with data argument of kthread_run( fun, data , NAME ); but this is not work I dont know why. I tried many possibility and nothing works. So I thought that... (0 Replies)
Discussion started by: marcintom
0 Replies
Login or Register to Ask a Question
PIPE(2) 							System Calls Manual							   PIPE(2)

NAME
pipe - create an interprocess channel SYNOPSIS
#include <u.h> #include <libc.h> int pipe(int fd[2]) DESCRIPTION
Pipe creates a buffered channel for interprocess I/O communication. Two file descriptors are returned in fd. Data written to fd[1] is available for reading from fd[0] and data written to fd[0] is available for reading from fd[1]. After the pipe has been established, cooperating processes created by subsequent fork(2) calls may pass data through the pipe with read and write calls. The bytes placed on a pipe by one write are contiguous even if many processes are writing. Write boundaries are preserved: each read terminates when the read buffer is full or after reading the last byte of a write, whichever comes first. The number of bytes available to a read(2) is reported in the Length field returned by fstat or dirfstat on a pipe (see stat(2)). When all the data has been read from a pipe and the writer has closed the pipe or exited, read(2) will return 0 bytes. Writes to a pipe with no reader will generate a note sys: write on closed pipe. SOURCE
/sys/src/libc/9syscall SEE ALSO
intro(2), read(2), pipe(3) DIAGNOSTICS
Sets errstr. BUGS
If a read or a write of a pipe is interrupted, some unknown number of bytes may have been transferred. When a read from a pipe returns 0 bytes, it usually means end of file but is indistinguishable from reading the result of an explicit write of zero bytes. PIPE(2)