Professional Documents
Culture Documents
Declaration:
I declare that this assignment is my individual work. I have not copied from any other student’s
work or from any other source except where due acknowledgement is made explicitly in the text,
nor has any part been written for me by another person.
Evaluator’s comment:
__________________________________________________________________________
PART-A
#include<unistd.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<stdlib.h>
int main()
char bl[20480];
int in,out;
int nread;
in=open("file.in",O_RDONLY);
out=open("file.out",O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
while((nread=read(in,block,sizeof(bl)))>0)
write(out,bl,nread);
exit(0);
#include<stdio.h>
#include<stdlib.h>
int main()
int c;
out=fopen("file.out","w");
while((c=fgetc(in))!=EOF)
fputc(c,out);
exit(0);
#include<unistd.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<stdlib.h>
int main()
char bl[16348];
int in,out;
int nread;
in=open("file.in",O_RDONLY);
out=open("file.out",O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
while((nread=read(in,block,sizeof(block)))>0)
write(out,block,nread);
exit(0);
2. WAP to read a ‘C’ program file and count the following in the program.
#include<unistd.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<stdlib.h>
#include<stdio.h>
int main()
char bl[20];
int count=0;
int nread;
in=open("file.in",O_RDONLY);
out=open("file.out",O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
while((nread=read(in,bl,sizeof(bl)))>0)
write(out,bl,nread);
count ++;
exit(0);
Ans:3
rmdir -p --ignore-fail-on-non-empty ./sources/glibc-build/
rm -rf ow
Q4. Illustrate through example in which scenario would you prefer using perror ( ) and in
which stderror ( ).
Answer: The perror() function shall map the error number accessed through the symbol errno to
a language-dependent error message, which shall be written to the standard error stream as
follows:
• First (if s is not a null pointer and the character pointed to by s is not the null byte), the
string pointed to by s followed by a colon and a <space>.
• Then an error message string followed by a <newline>.
The perror() function shall not change the orientation of the standard error stream.
The following example replaces bufptr with a buffer that is the necessary size. If an error occurs,
the perror() function prints a message and the program exits.
#include <stdio.h>
#include <stdlib.h>
...
char *bufptr;
size_t szbuf;
...
perror("malloc"); exit(2);
}
...
EXAMPLE:
/* perror example */
#include <stdio.h>
int main ()
{
FILE * pFile;
pFile=fopen ("unexist.ent","rb");
if (pFile==NULL)
perror ("The following error occurred");
else
fclose (pFile);
return 0;
}
Q5.Write a C program to input file name and change its permissions to reading by all and
writing by owner only.
ANSWER:
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
main()
{
pid_t pid;
char *parmList[] = {"/bin/chmod", "0700", "/home/op/biaoaai/bead",NULL};
Your Rollno
Previous
Next Rollno
Rollno
Answer:
1- Check which directory you are currently active in prior to using the "mkdir" command.
This will eliminate errors later if you are in a directory in which you don't have such
command privileges. You can check this by using the "pwd" command and pressing
"Enter."
2- Type "mkdir [directory]" at the command prompt to make the directory. Use the name of
your new directory in place of the [directory] command line operator. To create a
directory called "business," you would type "mkdir business." Be aware that this will
create the directory within the current working directory.
3- Use the "-p" command line parameter to create subdirectories within a parent directory.
For example, you would type "mkdir -p games/strategy/chess" to create a directory tree
including "strategy/chess" within the "games" directory.
4- Create a new directory in a directory other than the current working directory using the "-
p" command line parameter as you did to create a directory tree. In this manner however,
it is important to include the slash "/" prior to the first directory's name. In other words, if
you wanted to create a "chess" directory in a "games" directory that already exists you
would type "mkdir -p /games/chess."
5- Make multiple directories at once using the "mkdir" command. You can do this by
including a space in between each of the directories you intend to create. For example,
the command "mkdir -p games bin lib personal" would create a "games," "bin," "lib" and
"personal" directory all at once.