Computer Science, asked by priyasingh2302, 3 months ago

(A).

#include

int main(int argc, char *argv[]) {

int count = 0; // declaring variables

for(int i=1; i if(argv[i][0] != '-') // if it doesn't start with -, printing, counting
{
count++;
printf("%s ", argv[i]);
}
if(count > 0)
printf("\n");
}

(B)

#include
#include

main()
{
// variable to store the character
char c;
int count;
printf("Enter some character. Enter Ctrl + Z invoke EOF \n");

// reading input from stdin
while ((c = getchar()) != EOF)
{

// writing character entered to stdout
putchar(c);

// check if the number is alphabet
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
{
printf(" is alphabet \n");
}

// couting non alphabetic character including newline character
else
{
printf(" is not an alphabetic \n");
count++;
}
}
// printing the count of alphabetic characters on stderr using fprintf
fprintf(stderr, "The no of non alphabetic characters are : %d", count);
exit(0);
}

(C)

#include
#include
#include
int main(void){
int i=0;
char s,str[1000];

while(1){
s=getchar();
if(s==EOF){
break;
}

if(islower(s)){
s=toupper(s);
}

else if(isupper(s)){
s=tolower(s);
}

str[i]=s;
i++;

}
i++;
str[i]='\0';
printf("\n%s\n",str);
return 0;
}

You are to combine the C programs from (A), (B) and (C) that: (1) reads from the first file argument, reverses lowercase and uppercase letters, that is, makes lowercase all uppercase letters and vice versa, and writes out all characters, whether or not reversed; and (2) reads the above output, counts the number of NON-alphabetic characters (that is, those not in the a-z range nor in the A-Z range), and writes out all characters, whether counted or not, into its second file argument. So that you become familiar with the various LINUX system calls and libraries (fork, execl, pipe, create, open, close, dup, stdio, exit), you will write this program in a certain contrived fashion. The program will be invoked as ``driver file1 file2''. Both file arguments are required (print an error message on stderr using fprintf if either argument is missing and then exit(1)). The driver program will open the first file and creat the second file, and dup them down to stdin and stdout. The driver program sets up a pipe and then forks two children. The first child forked will dup the read end of the pipe down to stdin and then execl the program you have written, count, which will read characters from stdin, count the nonalphabetic ones (see /usr/include/ctype.h), and write all characters out to stdout. The count program uses only stdin and stdout, and only the stdio library routines (see stdio.h) for input and output (see getchar and putchar). The program will print out the final count on stderr using fprintf and then exit(0) when it hits EOF in its input. The second child forked will dup the write end of the pipe down to stdout and then execl the program you have written, convert, which will read characters from stdin, reverse uppercase and lowercase (again, see ctype.h), and write them all out to stdout. Like count, this program uses only stdin and stdout. Also, it uses only the stdio library routines. The program will exit(0) when it hits EOF in its input

The reason for creating the children in this order (first the one that reads from the pipe, usually called the second in the pipeline, and then second the one that writes to the pipe, usually called the first in the pipeline -- confusing!!) is that LINUX will not let a process write to a pipe if no process has the pipe open for reading; the process trying to write would get the SIGPIPE signal. So we create first the process that reads from the pipe to avoid that possibility. Meanwhile, the parent process, the driver, will close its pipe file descriptors and then call wait (see /usr/include/sys/wait.h) twice to reap the zombie children processes when they finish. Then the parent will exit(0). Remember to close all unneeded file descriptors, including unneeded pipe ones, or EOF on a pipe read may not be detected correctly. Check all system calls for the error return (- 1). For all error and debug messages, use ``fprintf(stderr, ...)'' or use the function perror or the external variable errno (see also /usr/include/errno.h). Declare a function to be of type void if it does not return a value, that is, if it is a subroutine rather than a true function. If you absolutely must ignore the output of a system call or function, then cast the call to void.

Answers

Answered by nishathakur5755
1

Answer:

pls mark me as brainlist the

Explanation:

thanks for free points

Answered by Anonymous
0

Answer:

The last wild population lived in the Orange Free State; the quagga was extinct in the wild by 1878. The last captive specimen died in Amsterdam on 12 August 1883. Only one quagga was ever photographed alive, and only 23 skins are preserved today. In 1984, the quagga was the first extinct animal whose DNA was analysed.

Similar questions