22.07.2013 Views

Download File

Download File

Download File

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Subject: NETWORK PROGRAMMING LAB Year : 2010<br />

Class : IV B-Tech C.S.E Semester: First<br />

WEEK 2:<br />

Aim: Implement the pipe using popen (), close () /* file name pipeopen.c */<br />

# include <br />

# include <br />

# include <br />

# define MAXLINE 4096<br />

# define PAGER "${PAGER:-more}"<br />

int main(int argc,char*argv[])<br />

{<br />

char line[MAXLINE];<br />

FILE *fpin,*fpout;<br />

if(argc!=2)<br />

{<br />

perror("\n usage :- a.out ");<br />

exit(0);<br />

}<br />

if((fpin=fopen(argv[1],"r"))==NULL)<br />

{<br />

printf("\nUnable to open %s",argv[1]);<br />

}<br />

if((fpout=popen(PAGER,"w"))==NULL)<br />

perror("popen error...");<br />

while(fgets(line,MAXLINE,fpin))<br />

{<br />

if(fputs(line,fpout)==EOF)<br />

perror("\n fput error...");<br />

}<br />

if(ferror(fpin))<br />

perror("fgets error...");<br />

if(pclose(fpout)==-1)<br />

perror("pclose error..");<br />

exit(0);<br />

}<br />

NP Lab Manual , RNEC page: 7

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!