Sponsored Content
Full Discussion: pipe program in C
Top Forums Programming pipe program in C Post 302473549 by beandj on Sunday 21st of November 2010 09:49:27 AM
Old 11-21-2010
pipe program in C

Hello guys,

my professor give me 2 days to study and make a program usign pipe, fork in c

i need to do a program

read a arq.txt
the father process read the file and the child print !

like this
Code:
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>

int main (){
        int std[2];
        FILE *fp;
        unsigned char c;
        pipe(std); 
        if(fork() == 0){ 
                close(0); 
                dup(std[0]); 
                close(std[0]);
                close(std[1]); 
                exit(0); 
        }else{
                close(1); 
                dup(std[1]); 
                close(std[0]); 
                close(std[1]); 
                if(fp = fopen("arq.txt", "rb")){ 
                        fscanf(fp, "%c", &c); 
                        while(!feof(fp)){ 
                                fprintf(stdout,"%c",c); 
                                fscanf(fp, "%c", &c);   
                        }
                        fclose(fp); 
                }
                wait(0); 
        }               
        return(0);
}

but the program doesn't work
and i dont know why

Last edited by jim mcnamara; 11-21-2010 at 11:12 AM.. Reason: code tags
 

10 More Discussions You Might Find Interesting

1. Programming

How to clear the content of a pipe (STDIN) after it is written to another program?

PROGRAM A <-> PROGRAM B PROGRAM A sends data as STDIN ro PROGRAM B and when PROGRAM B is executed from PROGRAM A, it sends output back to PROGRAM A. This is implemented using 2 pipes (fd1 & fd2). The above process happens in a loop and during the second run, the previous data that had been... (10 Replies)
Discussion started by: vvaidyan
10 Replies

2. Programming

C++ How to use pipe() & fork() with stdin and stdout to another program

Hi, Program A: uses pipe() I am able to read the stdout of PROGAM B (stdout got through system() command) into PROGRAM A using: * child -> dup2(fd, STDOUT_FILENO); -> execl("/path/PROGRAM B", "PROGRAM B", NULL); * parent -> char line; -> read(fd, line, 100); Question:... (2 Replies)
Discussion started by: vvaidyan
2 Replies

3. UNIX for Dummies Questions & Answers

Script to open program and send/execute command in program

Hi, i want to write a script that executes a program (exec?) . this program then requires a filename as input. how do i give it this input in the script so the program will be complete run and close by the script. e.g. exec prog.exe program then asks for filename "enter filename:"... (1 Reply)
Discussion started by: tuathan
1 Replies

4. Solaris

sendmail pipe to a program.

Hello, I recently upgraded our server from Solaris 8 to 9. The sendmail is unabled to pipe the email to a perl script. I can send and received email to local and external mail, but the script did not get the email. There is no error in the log and I could not find any thing on the web. Here... (0 Replies)
Discussion started by: ld98
0 Replies

5. Homework & Coursework Questions

pipe program in C

Hello guys, my professor give me 2 days to study and make a program usign pipe, fork in c i need to do a program read a arq.txt the father process read the file and the child print ! 2. Relevant commands, code, scripts, algorithms: like this Code: #include <stdio.h>... (1 Reply)
Discussion started by: beandj
1 Replies

6. Homework & Coursework Questions

Calling compiled C program with Perl program

Long story short: I'm working inside of a Unix SSH under a bash shell. I have to code a C program that generates a random number. Then I have to call the compiled C program with a Perl program to run the C program 20 times and put all the generated random #s into a text file, then print that text... (1 Reply)
Discussion started by: jdkirby
1 Replies

7. Shell Programming and Scripting

Replace pipe with Broken Pipe

Hi All , Is there any way to replace the pipe ( | ) with the broken pipe (0xA6) in unix (1 Reply)
Discussion started by: saj
1 Replies

8. Shell Programming and Scripting

How to ignore Pipe in Pipe delimited file?

Hi guys, I need to know how i can ignore Pipe '|' if Pipe is coming as a column in Pipe delimited file for eg: file 1: xx|yy|"xyz|zzz"|zzz|12... using below awk command awk 'BEGIN {FS=OFS="|" } print $3 i would get xyz But i want as : xyz|zzz to consider as whole column... (13 Replies)
Discussion started by: rohit_shinez
13 Replies

9. Shell Programming and Scripting

How to send data to previous program (pipe)?

Hi, Suppose I have a command:$ cmd1 | cmd2I need to send a message from cmd2 to cmd1 when I receive some a certain message from cmd1. How to do this? I think that I have to know cmd1's PID and then in cmd2 send a message to this PID. How? (24 Replies)
Discussion started by: JackK
24 Replies

10. 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
std::locale::facet(3)					     Library Functions Manual					     std::locale::facet(3)

NAME
std::locale::facet - SYNOPSIS
Inherited by std::__codecvt_abstract_base< _InternT, _ExternT, encoding_state >, std::__codecvt_abstract_base< char, char, mbstate_t >, std::__codecvt_abstract_base< wchar_t, char, mbstate_t >, std::__ctype_abstract_base< wchar_t >, std::__codecvt_abstract_base< _InternT, _ExternT, _StateT >, std::__ctype_abstract_base< _CharT >, std::__moneypunct_cache< _CharT, _Intl >, std::__numpunct_cache< _CharT >, std::__timepunct< _CharT >, std::__timepunct_cache< _CharT >, std::collate< _CharT >, std::ctype< char >, std::messages< _CharT >, std::money_get< _CharT, _InIter >, std::money_put< _CharT, _OutIter >, std::moneypunct< _CharT, _Intl >, std::num_get< _CharT, _InIter >, std::num_put< _CharT, _OutIter >, std::numpunct< _CharT >, std::time_get< _CharT, _InIter >, and std::time_put< _CharT, _OutIter >. Protected Member Functions facet (size_t __refs=0) throw () virtual ~facet () Static Protected Member Functions static __c_locale _S_clone_c_locale (__c_locale &__cloc) throw () static void _S_create_c_locale (__c_locale &__cloc, const char *__s, __c_locale __old=0) static void _S_destroy_c_locale (__c_locale &__cloc) static __c_locale _S_get_c_locale () static const char * _S_get_c_name () throw () static __c_locale _S_lc_ctype_c_locale (__c_locale __cloc, const char *__s) Friends class locale class locale::_Impl Detailed Description Localization functionality base class. The facet class is the base class for a localization feature, such as money, time, and number printing. It provides common support for facets and reference management. Facets may not be copied or assigned. Definition at line 338 of file locale_classes.h. Constructor &; Destructor Documentation std::locale::facet::facet (size_t__refs = 0) [inline], [explicit], [protected] Facet constructor. This is the constructor provided by the standard. If refs is 0, the facet is destroyed when the last referencing locale is destroyed. Otherwise the facet will never be destroyed. Parameters: __refs The initial value for reference count. Definition at line 370 of file locale_classes.h. virtual std::locale::facet::~facet () [protected], [virtual] Facet destructor. Author Generated automatically by Doxygen for libstdc++ from the source code. libstdc++ Tue Jun 10 2014 std::locale::facet(3)
All times are GMT -4. The time now is 07:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy