Thursday, July 28, 2011

TCP echo client

/* TCP echo client  tcp_echo_clnt.c */
#include "unp.h"

void
str_cli(FILE *fp, int sockfd)
{
char sendline[MAXLINE], recvline[MAXLINE];

while (Fgets(sendline, MAXLINE, fp) != NULL) {

Writen(sockfd, sendline, strlen(sendline));

if (Readline(sockfd, recvline, MAXLINE) == 0)
err_quit("str_cli: server terminated prematurely");

Fputs(recvline, stdout);
}
}

int
main(int argc, char **argv)
{
int sockfd;
struct sockaddr_in servaddr;

if (argc != 2)
err_quit("usage: tcpcli <IPaddress>");

sockfd = Socket(AF_INET, SOCK_STREAM, 0);

bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(SERV_PORT);
Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);

Connect(sockfd, (SA *) &servaddr, sizeof(servaddr));

str_cli(stdin, sockfd); /* do it all */

exit(0);
}

TCP echo server program

/* TCP echo server tcp_echo_ser.c */
#include "unp.h"

void
str_echo(int sockfd)
{
long arg1, arg2;
ssize_t n;
char line[MAXLINE];

for ( ; ; ) {
if ( (n = Readline(sockfd, line, MAXLINE)) == 0)
return; /* connection closed by other end */

n = strlen(line);
printf("\nReq From Client : %s",line);
Writen(sockfd, line, n);
}
}

int
main(int argc, char **argv)
{
int listenfd, connfd;
pid_t childpid;
socklen_t clilen;
struct sockaddr_in cliaddr, servaddr;

listenfd = Socket(AF_INET, SOCK_STREAM, 0);

bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(SERV_PORT);

Bind(listenfd, (SA *) &servaddr, sizeof(servaddr));

Listen(listenfd, LISTENQ);

printf("Server Running on Port %d\n", SERV_PORT);
for ( ; ; ) {
clilen = sizeof(cliaddr);
connfd = Accept(listenfd, (SA *) &cliaddr, &clilen);

if ( (childpid = Fork()) == 0) { /* child process */
Close(listenfd); /* close listening socket */
str_echo(connfd); /* process the request */
exit(0);
}
Close(connfd); /* parent closes connected socket */
}
}

Friday, July 22, 2011

TCP Iterative Client / Server Program to echo the text in reverse

/*
TCP iterative SERVER program
The following program shows the contents of Filename : TCP_it_ser.c.
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <unistd.h>

#define MYPORT 13153 /*The port users will be connecting to*/
void readstring(int,char *);
int main(int C, char *V[] )
{
int listensocket,connectionsocket,retbind;
struct sockaddr_in
serveraddress,cliaddr;
socklen_t len;
char buf[100],databuf[1024];
listensocket = socket(AF_INET, SOCK_STREAM, 0 );
if (listensocket < 0 )
{
perror("socket" );
exit(1);
}
memset(&serveraddress, 0, sizeof(serveraddress) );
serveraddress.sin_family = AF_INET;
serveraddress.sin_port = htons(MYPORT);/*PORT NO*/
serveraddress.sin_addr.s_addr =
htonl(INADDR_ANY);/*ADDRESS*/
retbind=bind(listensocket,(struct sockaddr*)&serveraddress,
sizeof(serveraddress));
/*Check the return value of bind for error*/
if(-1==retbind)
{
perror("BIND ERROR\n");
exit(1);
}
listen(listensocket,5);
/*Beginning of the Main Server Processing Loop*/
for (;;)
{
printf("Server:I am waiting-----Start of Main Loop\n");
len=sizeof(cliaddr);
connectionsocket=accept(listensocket,
(struct sockaddr*)&cliaddr,&len);
if (connectionsocket < 0)
{
if (errno == EINTR)
printf("Interrupted system call ??");
continue;
}
printf("Connection from %s\n",
inet_ntop(AF_INET,&cliaddr.sin_addr,buf,sizeof(buf)));
readstring(connectionsocket , databuf);
close(connectionsocket);
printf("Finished Serving One Client\n");
}
}

/***********************************************************
* FUNCTION NAME:readstring
* DESCRIPTION: Reads the string sent by the client over the
* socket and stores it in the array fname .
* NOTES : No Error Checking is done .
* RETURNS :void
***********************************************************/

void readstring(int connectionsocket,char *fname) /*Array , to be populated by the string from client*/
{
int pointer=0,n;
int len=0,a,b;
char rev[50],temp[50],temp1[50];
int k,i;
while ((n=read(connectionsocket,(fname + pointer),1024))>0)
{
pointer=pointer+n;
}
fname[pointer]='\0';
printf("enter the string\n");
printf("Server :Received %s\n " ,fname);
//strcpy(temp,fname);
k=strlen(fname);
// for(k=0;temp[k]!=0;k++);
// len=k;
a=0;
for(i=k-1;i>=0;i--)
temp[a++]=fname[i];
temp[a]='\0';
printf("\nrev is %s\n", temp);
}

/*
TCP ITERATIVE CLIENT program
The following program shows the contents of Filename : TCP_it_clnt.c.
*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
#define MAXBUFFER 1024
void sendstring(int , char *);

int main( int C, char *V[] )
{
int sd,fd;
char c;
struct sockaddr_in serveraddress;
char text[100];
int i=0;
sd = socket( AF_INET, SOCK_STREAM, 0 );
if( sd < 0 ) {
perror( "socket" );
exit( 1 );
}
if (V[1] == NULL ) {
printf ("PL specfiy the server's IP Address \n");
exit(0);
}
if (V[2] == NULL ) {
printf ("PL specify the server's Port No \n");
exit(0);
}
memset( &serveraddress, 0, sizeof(serveraddress) );
serveraddress.sin_family = AF_INET;
serveraddress.sin_port = htons(atoi(V[2]));//PORT NO
serveraddress.sin_addr.s_addr = inet_addr(V[1]);//ADDRESS
if (connect(sd,(struct sockaddr*)&serveraddress,
sizeof(serveraddress))<0)
{
printf("Cannot Connect to server");
exit(1);
}
printf("enter sentence to end enter #");
while(1)
{
c=getchar();
if(c=='#')
break;
text[i++]=c;
}
text[i]='\0';
sendstring(sd,text);
close(sd);
return 0;
}
/**********************************************************
* FUNCTION NAME:sendstring
* DESCRIPTION: sends a string over the socket .
* NOTES : No Error Checking is done .
* RETURNS :void
***********************************************************/
void sendstring(
int sd, /*Socket Descriptor*/
char *fname) /*Array Containing the string */
/**********************************************************/
{ int n , byteswritten=0 , written ;
char buffer[MAXBUFFER];
strcpy(buffer , fname);
n=strlen(buffer);
while (byteswritten<n)
{
written=write(sd , buffer+byteswritten,(n-byteswritten));
byteswritten+=written;
}
printf("String : %s sent to server \n",buffer);
}
/***********************************************************/




/*

Execution & results:
1. Compiling and running server.

[user@localhost rvs]$ cc tcpserver.c
[user@localhost rvs]$ mv a.out tcpserver
[user@localhost rvs]$ ./tcpserver
Server:I am waiting-----Start of Main Loop
Connection from 127.0.0.1
enter the string
Server :Received Network Programming
Rev string is gnimmargorP krowteN
Finished Serving One Client
Server:I am waiting-----Start of Main Loop
2. Compiling and running client.

[user@localhost rvs]$ cc tcpclient.c
[user@localhost rvs]$ mv a.out tcpclient
[user@localhost rvs]$./tcpclient 127.0.0.1 13153
enter sentence to end enter #Network Programming#
String : Network Programming sent to server

*/

Thursday, July 21, 2011

Program to create an integer variable using shared memory concept & increment it simultaniously by two processes.Use semaphores to avid race conditions

#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <string.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>
#include <sys/sem.h>
# include <stdlib.h>

#define SHMSZ 4 /* Good for integer */
#define BUF_SZ 16
#define SHM_KEY 1234
#define SEM_KEY 1235
#define CHILD_INCREMENT_COUNT 67787
#define PARENT_INCREMENT_COUNT 84823

union semun {
int val; /* value for SETVAL */
struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */
unsigned short *array; /* array for GETALL, SETALL */
/* Linux specific part: */
struct seminfo *__buf; /* buffer for IPC_INFO */
};


main()
{
int shmid;
int semid;
key_t key;
int *child_shm, *parent_shm;
union semun arg;
int i;
struct sembuf operations[1];
int status;
int pid;

/*
* Create the shared segment.& semaphore.
*/
if ((shmid = shmget(SHM_KEY, SHMSZ, IPC_CREAT | 0666)) < 0) {
perror("shmget");
exit(1);
}

if ((semid = semget(SEM_KEY, 1, IPC_CREAT | 0666)) < 0) {
perror("semget");
exit(1);
}

/*
* Initialize the semaphore to value 1. The idea is multiple processes
* do semop() of -1. So only one is allowed in critical section.
* initialize the shm to 0.
*/
arg.val = 1;
if (semctl(semid, 0, SETVAL, arg) < 0) {
perror("semctl");
exit(1);
}

if ((parent_shm = shmat(shmid, NULL, 0)) == (int *)-1) {
perror("parent shmat");
exit(1);
}

*parent_shm = 0;

/*
* create a child process. The above opened shm & sem fds get
* copied to child process as a result of fork(). They both attach to the
* shared memory and use the semphore to increment the value in the shm.
*/

if ((pid = fork()) < 0) {
printf("Child Process Creation Error:%d\n", errno);
return;
}

/*
* Child process attaches to shm. It fill operations to block till
* it gets -1. Since the initial value of semaphore is 1, only one
* process can do -1. The other process will see the value as 0 and
* block till it sees sem value as 1. After semop(), increment the shm
* integer by 1. Then again use the semop to set the sem value to 1, so
* that other process gets the chance to run.
* Repeat the above for a defined number of times. Later similar thing is
* done for parent process also.
*/

if (pid == 0) {

if ((child_shm = shmat(shmid, NULL, 0)) == (int *)-1) {
perror("child shmat");
exit(1);
}

for (i = 0; i < CHILD_INCREMENT_COUNT; i++) {

operations[0].sem_num = 0;
operations[0].sem_op = -1;
operations[0].sem_flg = 0;

if (semop(semid, operations, 1) < 0) {
perror("child semop");
exit(1);
}

*child_shm = *child_shm + 1;

if (i%1000 == 0) {
usleep(1); // sleep 1 us to increase window of critical section
}

operations[0].sem_num = 0;
operations[0].sem_op = 1;
operations[0].sem_flg = 0;

if (semop(semid, operations, 1) < 0) {
perror("child semop");
exit(1);
}

}

}


if (pid != 0) {

for (i = 0; i < PARENT_INCREMENT_COUNT; i++) {

operations[0].sem_num = 0;
operations[0].sem_op = -1;
operations[0].sem_flg = 0;

if (semop(semid, operations, 1) < 0) {
perror("parent semop");
exit(1);
}

*parent_shm = *parent_shm + 1;

if (i%1500 == 0) {
usleep(1); // sleep 1 us to increase window of critical section
}

operations[0].sem_num = 0;
operations[0].sem_op = 1;
operations[0].sem_flg = 0;

if (semop(semid, operations, 1) < 0) {
perror("parent semop");
exit(1);
}

}

// wait for child to complete
wait(&status);

/*
* now that parent and child are done incrementing, check the
* consistency of the shm memory.
*/

printf("Child Incremented %d times, Parent %d times. SHM Value %d\n",
CHILD_INCREMENT_COUNT, PARENT_INCREMENT_COUNT, *parent_shm);
if (*parent_shm == (CHILD_INCREMENT_COUNT + PARENT_INCREMENT_COUNT)) {
printf("Total of Parent & Child matches SHM value\n");
} else {
printf("BUG - Total of Parent & Child DOESNT match SHM value\n");
}
}

exit(0);

}


Wednesday, July 20, 2011

Infosys Campus Connect Pre test for rnec students dt 19/7/2011



RAO & NAIDU ENGINEERING COLLEGE
CAMPUS CONNECT PROGRAM PRE TEST
Date: 19-07-2011

Roll No : 0_771A05_ _                                          Section : IV CSE A/B

Answr all , each carries 1 mark                                             Max Marks : 20 ,Time :30 min

1 .Convert the expression ((A + B) *  C – (D – E) ^ (F + G)) to equivalent Prefix  notations.  [   ]

a) ^ - * +ABC - DE + FG  b) + ^AB + C * DE - - FG   c) - ^* ABC - DE + FG  +  d)none     
           
2. In general ,if  there are n nodes, there exist ________________ different trees.                   [   ]
a) 2n-1                     b) 2n-n              c) 2n-1- n            3) 2n+1-n

3. while(1) { printf(“X”);}  output is                                                                                           [    ]
a)XXXXXX    b)XXXXX     c)XXXXXX      d)idefinate loop prints XXXXXXX……       

4. DCL stands for                                                                                                                        [    ]
a)Data connection Language   b)Data commission Language
c)Data Control Language        d)Data Language For Control

5.Views are                                                                                                                                  [    ]
            a)stored queries    b)stored tables      c)stored database       d)stored indexes

6.Name the three major set of files on disk that compose a database in Oracle                          [    ]
a)      Database files b) Control files  c) Redo logs d)all

7. An abstract class is?
            a) A generalized class b) A specialized classes  c) An Interface                                          [    ]
            d) one method should be abstract method

8. Which of the below testing is an example for validation
            a) unit testing  b)Integration testing c)system testing d)alpha testing                             [   ]

9. Date class exists in which package ?                                                                                                
            a)lang             b)io     c)util   d)sql

10. An IPV4 address consist of -------- bits                                                                                         [   ]
            a)32 b)64 c) 48 d)52

11. which socket structure belongs to IPV4 family.                                                                           [   ]
            a)sockaddr{} b)sockaddr_in{}       c)sockaddr_un{}      d)sockaddr_in4{}


12.which is a connection less protocol ?                                                                                      [   ]
            a)TCP              b)UDP             c)ARP                         d)IP    



13. Which of the following memories has the shortest access time?                                                      [   ]
a) Cache memory b) Magnetic bubble memory c) Magnetic core memory d) RAM

14. Virtual memory size depends on                                                                                          [   ]
a) address lines    b) data bus  c) disc space       d)  a & c   



15. Context switch takes place when process                                                                             [   ]
            a) blocks          b)i/o interrupt occurs   c)terminates     d)all

16. A shift register can be used for                                                                                             [   ]
(a) Parallel to serial conversion
(b) Serial to parallel conversion
(c) Digital delay line
(d) All the above

17.  In a processor these are 120 instructions . How many bits needed to   implement   these instructions.                                                                                                                                [   ]
    a) 6              b) 7      c) 10    d) none

18. In an absolute loading scheme, which loader function is accomplished by assembler        [   ]
a) Reallocation
b) Allocation
c) Linking
d) Both (a) and (b)
19.  Piggy backing is a  technique for                                                                                         [   ]
a) Flow control
b) Sequence
c) Acknowledgement
d)  retransmition

20. What is the max. decimal number that can be accomodated in a byte.                              [   ]
a) 128
b) 255
c) 256
d) 512

for key  www.rnec.org

Answer key for campus connect pre test dt: 19-07-2011 3 P.M.

Q.No               Ans
___________________
1                      a
2                      b
3                      d
4                      c
5                      a
6                      d
7                      a/d [ who's option 'd' they are real persuers]
8                      d
9                      c
10                    a
11                    b
12                    b
13                    a
14                    a
15                    d
16                    d
17                    b
18                    d
19                    c
20                    b
_____________________________
any queries mail ravinuthalavs@gmail.com


rvs
cse dept
Rao & Naidu engg college
           



Friday, July 15, 2011

sock_ntop() user def function for conversion

/*
sock_ntop() user def function for conversion
SOURCE CODE FOR AF_INET  */

char *SOCK_ntop(const struct sock_addr *addr *sa, socklen_t slen)
{
char portstr[7];
static char str[128]; /* unix domain is largest */
switch(sa->sa.family)
{
case AF_INET:{ struct sockaddr_in *sin=(struct sockaddr_in*)sa;
if(inet_ntop(AF_INET, &SIN->sin_addr,str,sizeof(st)==NULL)
return NULL;
if(ntoh s(sin->sin_port)!=0){
sprintf(portstr, sizeof(portstr),"%d",ntoh s(sin->sin_port);
strcat(str,strport);}
return str;
}

Thursday, July 14, 2011

Server program to recieve File using msg Q's IPC

/* msgrecvQ.c */

# include <stdio.h>
# include <string.h>
# include <sys/stat.h>
# include <sys/msg.h>
# include <sys/ipc.h>
# include <sys/types.h>

//message structure

struct message
{
long msg_type;
char msg_data[1024];
};
int main(int argc,char*argv[])
{
FILE*f;
int x,y,i=0;
char ch;
struct message msg_obj2={100,"M"};
int msg_id;

//creating msg q id
if((msg_id=msgget(1234,0644))==-1)
perror("\nUnable to get message id...");
else
printf("\nmsgid=%d",msg_id);

/* rec message from q*/
if((y=msgrcv(msg_id,&msg_obj2,1024,100,MSG_NOERROR))==-1)
perror(":- msgrcv error...");
else
printf("\nRec Bytes : %d",y);

if((f=fopen(argv[1],"w"))==NULL)
perror("\nUnable to open file for writing...");
else
{
for(i=0;msg_obj2.msg_data[i]!=0;i++)
{
putc(msg_obj2.msg_data[i],f);
}
fclose(f); //closing file
}
return 0;
}

Client file for file sending using IPC Q's

/* msgsendQ.c */

# include <stdio.h>
# include <string.h>
# include <sys/stat.h>
# include <sys/msg.h>
# include <sys/ipc.h>
# include <sys/types.h>

struct message
{
long msg_type;
char msg_data[1024];
};

int main(int arc,char*argv[])
{
//message structure
FILE*f;
int x,y,i=0;
char ch;
int key=1234;
int msg_id;
struct message msg_obj1={100,"I"};

//function to put file to message Q
if((f=fopen(argv[1],"r"))==NULL)
perror("\nUnable to open file for reading...");
else
{
while((ch=getc(f))!=EOF)
{
msg_obj1.msg_data[i++]=ch; //writing to msg_data
}
fclose(f); //closing file
}

//creating msg q id
if((msg_id=msgget(key,IPC_CREAT|0644))==-1)
perror("\nUnable to get message id...");
else
printf("\nmsgid=%d",msg_id);

/*writing message to the q */
if((x=msgsnd(msg_id,&msg_obj1,strlen(msg_obj1.msg_data),IPC_NOWAIT))==-1)
perror("\nUnable to send message...");
else
printf("\nSend Msg Success : return %d",x);

return 0;
}

Wednesday, July 13, 2011

Program to print the byte order of the system

/* Program to  print the byte order of the system whether little endian order or big endian order */
/* filename : byteorder.c */

#include"unp.h"

int main(int argc,char **argv)

{

union{

short s;

char c[sizeof(short)];

}un;

un.s=0x0102; /*int 2b value*/

printf("%s",CPU_VENDOR_OS);

if(sizeof(short)==2)

{

if(un.c[0]==1&&un.c[1]==2)

printf("big-endian \n");

else if(un.c[0]==2&&un.c[1]==1)

printf("little endian \n");

else

printf("unknown\n");

}

else

printf("sizeof(short)=%d",sizeof(short));

exit(0);

}

Monday, July 11, 2011

RVS_SOLUTIONS: File Transaction Using Message Q's IPC

RVS_SOLUTIONS: File Transaction Using Message Q's IPC: "//message file transaction # include # include # include # include ..."

File Transaction Using Message Q's IPC

//message file transaction


    # include <stdio.h>
    # include <string.h>
    # include <sys/stat.h>
    # include <sys/msg.h>
    # include <sys/ipc.h>
    # include <sys/types.h>

    //message structure
   
    struct message
    {
    long msg_type;
    char msg_data[1024];
    };
    //global objects
    struct message msg_obj1={100,"I"};
    struct message msg_obj2={100,"M"};
    //global msg id
    int msg_id;
   
    //function to put file to message Q
    putToMessageQ(char*fn)
    {
    FILE*f;
    int x,y,i=0;
    char ch;
    if((f=fopen(fn,"r"))==NULL)
    perror("\nUnable to open file for reading...");
    else
    {
        while((ch=getc(f))!=EOF)
        {
        msg_obj1.msg_data[i++]=ch; //writing to msg_data
        }   
        fclose(f); //closing file
    }
       
    //creating msg q id
    if((msg_id=msgget(1234,IPC_CREAT|0644))==-1)
    perror("\nUnable to get message id...");
    else
    printf("\nmsgid=%d",msg_id);

    /*writing message to the q */
    if((x=msgsnd(msg_id,&msg_obj1,strlen(msg_obj1.msg_data),IPC_NOWAIT))==-1)
    perror("\nUnable to send message...");
    else
    printf("\nSend Msg Success : return %d",x);

    }

    //function to transfer the file

    getFromMessageQ(char*fn)
    {

    FILE*f;
    int x,y,i=0;
    char ch;

    /* rec message from q*/
    if((y=msgrcv(msg_id,&msg_obj2,15,100,MSG_NOERROR))==-1)
    perror(":- msgrcv error...");
    else
    printf("\nRec Bytes : %d",y);

    if((f=fopen(fn,"w"))==NULL)
    perror("\nUnable to open file for writing...");
    else
    {
        for(i=0;msg_obj2.msg_data[i]!=0;i++)
        {
        putc(msg_obj2.msg_data[i],f);
        }   
        fclose(f); //closing file
    }
    return 0;   
    }
       
   
    int main(int argc,char*argv[])
    {
    putToMessageQ(argv[1]);
    getFromMessageQ(argv[2]);
    return 0;   
    }


       
       

Message text Transfor using IPC Message Q's

/* msg text trans using message Qs (IPC )<F3><F2

/* msg_tra_q.c compiled by RVS RNEC */

    # include <stdio.h>
    # include <string.h>
    # include <sys/stat.h>
    # include <sys/msg.h>
    # include <sys/ipc.h>
    # include <sys/types.h>
    # include <fcntl.h>
   
    struct message
    {
    long msg_type;
    char msg_data[1024];
    };
    struct message msg_obj1={100,"I Love Unix"};
    struct message msg_obj2={100,"M"};

    int main(int argc,char*argv[])
    {
    int msg_id,x,y;
    //creating msg q id
    if((msg_id=msgget(IPC_PRIVATE,IPC_CREAT/0644))==-1)
    perror("\nUnable to get message id...");
    else
    printf("\nmsgid=%d",msg_id);

   

    /*writing message to the q */
    if((x=msgsnd(msg_id,&msg_obj1,strlen(msg_obj1.msg_data),IPC_NOWAIT))==-1)
    perror("\nUnable to send message...");
    else
    printf("\nSend Msg Success : return 0");

   
    /* rec message from q*/
    if((y=msgrcv(msg_id,&msg_obj2,12,100,MSG_NOERROR))==-1)
    perror(":- msgrcv error...");
    else
    printf("\nRec Bytes : %d",y);

   
    printf("\nThe Message :-\n%s",msg_obj2.msg_data);
    return 0;   
       
    }


       
       

Monday, July 4, 2011

popen() function example

// popen()  function to open pipe

# include <sys/wait.h>
# include <stdio.h>
# include <stdlib.h>
# define MAXLINE 4096

# define PAGER "${PAGER:-more}"

int main(int argc,char*argv[])
{
char line[MAXLINE];
FILE *fpin,*fpout;
if(argc!=2)
{
perror("\n usage :- a.out <path name>");
exit(0);
}
if((fpin=fopen(argv[1],"r"))==NULL)
{
printf("\nUnable to open %s",argv[1]);
}
if((fpout=popen(PAGER,"w"))==NULL)
perror("popen error...");

while(fgets(line,MAXLINE,fpin))
{
if(fputs(line,fpout)==EOF)
perror("\n fput error...");
}

if(ferror(fpin))
perror("fgets error...");
if(pclose(fpout)==-1)
perror("pclose error..");
exit(0);
}