using fork and pipe
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > using fork and pipe




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    using fork and pipe  
Bhavin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-28-07 06:24 PM

i need to implement a program which will squeeze all the redundant
white space , new line character, and tab, program is just read one
file perform above task and display it.
That thing i already did, problem is that i need to create one child
process which will read one character at a time and it will return the
result to parent process using pipe to display it(i.e parent will
print the character ) and repeat the process.

I already coded it and getting some error please help me to solve the
error....... Thank you

#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
int MAX = 100;
int main(int argc, char *argv[])
{
FILE *fopen(), *fp;
char c[MAX];
char strr[MAX];
int count1;
int pipe_fd[2];
if (pipe(pipe_fd) < 0)
{
perror("Pipe call");
return(1);
}

if( argc > 2 )
printf(" Too Many arguement. \n");

fp = fopen( argv[1], "r" );

if ( fp == NULL )
{
printf("Cannot open %s for reading \n", argv[1] );
exit(0);
}

count1 = 1 ;
c = getc( fp ) ;

while ( c != EOF )
{
if ( c == ' ' )
{
putchar(c);
count1=count1+1;
if ( count1 == 26 )
{
count1 = 1;
printf("\n");
}
c=getc(fp);
while(c == ' ')
{
c=getc(fp);
}
}
if ( c  ==  '\n' || c == '\t' )
{
while( c  ==  '\n' || c == '\t' )
{
c=getc( fp );
}
}

if ( c  !=  '\n' || c != '\t' || c != ' ' )
{
//			putchar( c ) ;		/* Display character */
write(pipe_fd[1], c, strlen(c));
close(pipe_fd[1]);
count1 = count1+ 1 ;
c = getc ( fp );
if ( count1 == 26 )
{
count1 = 1;
printf("\n");
}
}
read(pipe_fd[0], strr, 1);
printf("%s", strr);
close(pipe_fd[0]);
}
fclose( fp );
}






[ Post a follow-up to this message ]



    Re: using fork and pipe  
Daniel C. Bastos


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-29-07 12:21 AM

Bhavin <v2desperado@gmail.com> writes:

> i need to implement a program which will squeeze all the redundant
> white space , new line character, and tab, program is just read one
> file perform above task and display it.

Okay.

> That thing i already did, problem is that i need to create one child
> process which will read one character at a time and it will return the
> result to parent process using pipe to display it(i.e parent will
> print the character ) and repeat the process.

Read a line, operate on it, and repeat. Why all the complication above?





[ Post a follow-up to this message ]



    Re: using fork and pipe  
Bhavin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-29-07 12:21 AM

On Sep 27, 5:37 pm, dbas...@yahoo.com.br (Daniel C. Bastos) wrote:
> Bhavin <v2desper...@gmail.com> writes: 
>
> Okay.
> 
>
> Read a line, operate on it, and repeat. Why all the complication above?

because that is what i have to do, i know i can use read line but they
want it character wise, please if you can help me, I really
appreciatted your effort






[ Post a follow-up to this message ]



    Re: using fork and pipe  
Scott Lurndal


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-29-07 12:21 AM

Bhavin <v2desperado@gmail.com> writes:
>On Sep 27, 5:37 pm, dbas...@yahoo.com.br (Daniel C. Bastos) wrote: 
>
>because that is what i have to do, i know i can use read line but they
>want it character wise, please if you can help me, I really
>appreciatted your effort
>

Please ask your TA or professor to help you first.

scott





[ Post a follow-up to this message ]



    Re: using fork and pipe  
Barry Margolin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-29-07 06:47 AM

In article <1191001526.973942.324910@50g2000hsm.googlegroups.com>,
Bhavin <v2desperado@gmail.com> wrote:

> i need to implement a program which will squeeze all the redundant
> white space , new line character, and tab, program is just read one
> file perform above task and display it.
> That thing i already did, problem is that i need to create one child
> process which will read one character at a time and it will return the
> result to parent process using pipe to display it(i.e parent will
> print the character ) and repeat the process.
>
> I already coded it and getting some error please help me to solve the
> error....... Thank you

What is "some error"?

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 07:11 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register