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.



Ch-10 Structure and Union


MCQ
Which of the following cannot be checked in a switch-case statement?
A) Character
B) Integer
C) Float
 D) enum
True false
1. Does the data type of all elements in the union will be same?
2.. typedef is used to give a new name to a known data type.
3. In a union, space is allocated to every member individually.
4. The size of a structure can be determined by both size of variable name and size of (struct tag).
5. Structures can have bit fields.
6.  A structure can contain similar or dissimilar elements.
7. A structure can contain similar or dissimilar elements
8. A structure can contain pointer to itself.
9. Size of all elements in a union should be same.
10. Size of a pointer is equal to the data type it points to.

Match the following
1.        
union
a)       
Is different memory location that is used by several different variables, which may be of different type
2.        
typedef
b)       
Is  a memory location that is used by several different variables,which may be of different type
3.        
A self refrential structure is
c)        
Can be used to create variables of old types
4.        
This concept is borrowed from structure for constructing data type.
d)       
Contains pointer to itself.
5.        
structure
e)       
Array
6.        
The purpose of library function fflush() is
f)        
structure
7.        
A group of related data items
g)       
union
8.        
Structure in c Can be used with
h)       
To clear the specified buffer
9.        

i)         
union
10.    
P->member_name
j)         

11.    
Space for one member only
k)       
(*p).member_name

Fill in the blanks
A.       
unary
B.       
pointer
C.       
typedef
D.       
(*t)
E.        
enum
F.        
typeDef
G.      
semicolon
H.       
Void pointer
I.         
structure
J.         
semicolon
K.       

L.        
declaration
M.     

N.      

O.      

P.       


1. _________keyword is ued to declare user-defined data type.
2. _______is used to club variables of different data types as a unit.
3. type-casting is a _______operator.
4. __________keyword allows user to define  an identifier that would represent an existing data type.
5. All buffers are cleared when a ____________closed.
6. for_____and static variables,initializers must be constant expression.
7. if “t” is a pointer to a structure then “t->” is the same as_________.
8. the statement struct point {int x,y;}is a structure_____________.
9. The closing brace of a structure is followed by ____________.
10. structure definatin must be end with ___________.
Q/A
1. Write a program to copy a file into another file.
2. Write a program to create a structure Employee having empCode, name, department, address and salary as its members. Read the details for 10 employees and then display them.
3. Write a C program to find size of structure without using sizeof operator
4.  Enumerate the difference between: i) structures and union ii) union and enum
5.  Write a program which asks the user to enter the name and age of persons in his group. The numbers of persons is not known to the user in the beginning of the program. The user keeps on entering the data till the user enters the age as zero. The program finally prints the average age.
6. Define a structure of student with the following fields: rollNo, name and marks. Write a program to read and store the data of at most 30 students in an array. Also display the average marks of the students.
7.  Define two structures Metric and British that store distances. The Metric stores values in meters and centimeters and the British stores values in feet and inches. Write a program that reads both structure variables and add values contained in one variable of Metric to the contents of another variable of British. The program should display the result in both: equivalent centimeters and equivalent inches.
8. What is meant by structure data type? How do we reference the elements of a structure? Give example of how a value of a structure can be assigned to another structure.
9. Define a structure of employees of an organization with the following fields: Empno, Empname, Date_of_joining, Salary, Department Write a program which accepts names of ten employees and print them on the screen.
10. Write a program which asks the user to enter the name and age of persons in his group. The number of persons is not known to the user in the beginning of the program. The user keeps on entering the data till the user enters the age as zero. The program finally prints the average age.
11. Define a structure that describes a hotel. It should have members that include the name, address, grade, average room charge and number of rooms. Write a function to perform the following tasks.
12. Define a structure Time having integer data members hour, minute, second. Write a program to enter two variables of the type Time and then add these two variables and store the result into third variable. Also validate the second and minute of the result and print it.
13.  What is union data type? Define a union ‘u’ to hold a integer, float and character variable







ch-12 File Handling

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