Wednesday, 27 June 2018

ch-12 File Handling


Mcq
1. What does fp point to in the program?
 #include<stdio.h>
int main()
{
 FILE *fp;
 fp=fopen("trial", "r");
 return 0;
}
A) The first character in the file
B) A structure which contains a char pointer which points to the first character of a file
C) The name of the file
D) The last character in the file
2 Built-in data structures in ‘C’ are
A) Arrays
B) Structures
C) Files
D) All of the above
3.  If a file is open in ‘write’ mode, then
A) If it does not exist, an error is returned
B) If it does not exist, it is created
C) If it exists, then data is written at the end
D) If it exists, error is returned

4.  In the following ‘C’ code
{
FILE *f = fopen( fileName, "r");
fread(f);
if(????)
 puts(“End of file reached”);
}
Which one of the following can replace the ???? in the code above to determine if the end of
a file has been reached?
A) f == EOF
B) feof( f )
C) eof( f )
D) f == NULL
5.  If a file is opened in ‘write’ mode, then
A) If it does not exist, an error is returned
B) If it does not exist, it is created
C) If it exists, then data is written at the end
D) If it exists, error is returned
True false
1. The fprintf() function can be used to display the output on the screen.
2. The statement fopen("data.txt", "w+") will open a file named data.txt for both reading and writing
3.  Names of functions in two different files linked together must be unique.


Match the following
1.        
This character is used to indicate end of file
a)       
Time taken by read write head mechanism to position itself over appropriate cylinder.
2.        
A direct file is
b)       
Fseek()
3.        
Seek time is
c)        
“%[^\n]”
4.        
File pointer movement
d)       
EOF
5.        
Reading line with scanf()
e)       
getc
6.        
Gives the current position in the file
f)        
Files that are stored on a direct medium
7.        
Function  that detects error in file accessing
g)       
Ftell()
8.        
This function is used to read a character from a file
h)       
Ferror()
9.        
fseek
i)         
Is not portable
10.    
Binary file
j)         
Random access in the file; file specified trough file pointer.
11.    
Return type of ftell function
k)       

12.    

l)         

13.    

m)     
long

Fill in the blanks
A.       
fseekf
B.       
fprintf
C.       
fseek
D.       
fseek
E.        
fputs
F.        
Getw()
G.      
Linker
H.       
Fclose()
I.         
Fseek(fp,0L,0)
J.         
fputc
K.       
Randomly
L.        
EOF
M.     
long
N.      

O.      

P.       

Q.      

R.       


1. __________combines one or more object files and library code into executable file.
2. __________function is required to access data in a file in random manner.
3. function ______repositions the file position pointer to the beginning of the file.
4. ___________can be used to write in a file.
5. ____________function is used to move the file position   to desired location within the file
6. function_____writes a line to a specified file.
7. function_____writes a character  to a specified file.
8. function used to close a file is ____________.
9. the function________reads an integer from  a file.
10 the function lseek p[rovide a way to read or write a file in _________order.
11. The function getchar() returns _______when there is no more input character.
12. rewind (fp)and ________performs the same operation.
13. ftell() function returns _____type of data.
Q/A
1. Write a C program to write a line of string in a text file.
2. Explain the difference between text mode and binary mode files. c) Write a program to copy a file into another file.
3. Write a program to copy a file into another file.
4. How to create a file in C? Why should a user close the file?
5. Write a program that copies contents of a text file into another file. Use command line arguments to enter source and destination file name. If source file does not exist print appropriate message and terminate the program.
6.  Write a ‘C’ program to copy data of one file to another file.
7. Write a ‘C’ Program to create a file of numbers and copy odd number into second file and even number into third file.
8. Write a ‘C’ program to create a file of integers. The file name is given by the user. The second input to the program is the number ‘n’ of positive integers to be written into the file starting from 1.



1 comment:

ch-12 File Handling

Mcq 1. What does fp point to in the program?   #include<stdio.h> int main() {   FILE *fp;   fp=fopen("trial",...