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 ]
|