i need to find a way to print the number of arguments --- example ----
./a02 er t r
child process : counts four argument ----
what the output is now ---- er ; t;r;
and problem 2)
how can i make a call to reader for every character----instead of how i am doing it now---
each character should be a call to reader...
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
void writer (const char* message, int count, FILE* stream)
{
for (; count > 0; --count) {
fprintf (stream, "%s\n", message);
fflush (stream);
sleep (1);
}
}
void reader (FILE* stream)
{
int temp,temp1;
char buffer[1024];
while (!feof (stream)
&& !ferror (stream)
&& fgets (buffer,sizeof (buffer), stream) != NULL)
{
while(buffer<0)
{
temp++;
}
// printf("%d\n",temp);
fputs (buffer,stdout);
}
}
int main (int argc,char **argv)
{
int fds[2];
pid_t pid;
int i =0;
pipe (fds);
pid = fork ();
if (pid == (pid_t) 0) {
FILE* stream;
close (fds[1]);
stream = fdopen (fds[0], "r");
reader (stream);
close (fds[0]);
}
else {
FILE* stream;
close (fds[0]);
stream = fdopen (fds[1], "w");
while(i < (argc-1)){
i++;
writer (argv[i], 1, stream);}
close (fds[1]);
}
return 0;
}