C PROGRAMMING
MULTIPLE CHOICE QUESTION
OLD QUESTION BANK
SAMPLE QUESTION 2080 AND SOLUTION

ASSIGNMENT 9 :FILE 

  1. WAP to create a file named “test.txt” and write text” welcome to my college” to this file.(fputs)

 

  1. WAP to open the file “test1.txt” created in question 1 and read its contents and display them to the screen.(fgets)

 

  1. WAP to create a file and write some text to it, writing one character at a time using the fputc() function. The program should write until the user hits the enter key. Read filename from user.

while(c=getchar())!=’\n’)

fputc(c,fptr)

 

  1. WAP to open the file created in question 3, read its content one character at a time and display it to the screen.

 

  1. WAP to append some text to a file. Your program should take the name of the file from the user.
  2. Create a program which asks a file name from the user and create it to write some lines of text. Your program should write the text file until the user presses an enter key at the beginning of the line. Read the contents of the file and display it on the computer screen of the computer.
  3. WAP that opens a file and copies all its content to another file . Your program should read the name of the source and destination file from the user.
  4. WAP  to create a file named student.txt in D:\ drive and write the name,roll,address and marks of a student to the file.
  5. WAP to write even numbers between 10 and 50 to a file named evennumbers.txt in D:\ drive.
  6. WAP that asks a filename from the user and creates it to write some lines of text. Your program should  write the text until the user presses an enter key at the beginning of line. Read the content of the file and display it on the computer screen of the computer.
  7. WAP to create a data file and write the natural numbers from 1 to 20 to the file then read the numbers from the file to display the twice of stored numbers.
  8. WAP that opens a file and copies all its content to another file. Your file should read the name of the source and destination file from the user.
  9. WAP to read the content of  a file  created above , and display it on screen.
  10. WAP to open a file named ”product.txt” and store the following data to the file.(fprintf)

Product Name Quantity Rate

AAA 3 50

BBB 5 150

CCC 7 40

  1. WAP to open a file named “product.txt” created in q no.12 and read data from the file and display product table with total amount [i.e. rate*quantity] of each item.(fscanf)
  2. Create a structure named Employee that has name,address and salary as member . Assume appropriate types and size of members. Use this structure to read and display records of 3 Employees. Write an array of structure to a file and then read its content to display to the screen.[structure, fread,fwrite]
  3. WAP that create a file called “number.txt”, write an array of 10 digit integer number  into the file , again read the array stored in it and display to the screen.[array fread fwrite]
  4. WAP to take 10 integers as input and perform the following
  1. Display the sum of all integers
  2. Write odd numbers from those 10 integers to file “odd.txt”
  3. Write even numbers from 10 integers to file even.txt
  4. Read “even.txt” and “odd.txt” files and display them on screen.

17. A book record consists of its title,author,pages and price. WAP to perform the following operations:

  1. Read the record of 13 books.
  2. Create at least one structure pointer to display the record of 13 books.
  3. Store records of all 13 books in the file “booklist.txt”
  4. Read only the information of 9 books from booklist.txt skipping 2 books from first and 2 books from last and display them in terminal.

18. Create a structure named employee having empName, age and salary as its members . Read name,age and salary of a number of employees and write these data to a file named employee.txt . Read employee information again and again until the user wants to add more employees. Finally write a program to search information of a particular employee from the file.

19. Create a file named “hotel.txt”. WAP to keep the records of N hotels in Nepal to the file. These records should contain the name,location,and phone number of the respective hotel. Display the names of hotels in Pokhara Location.

20. Create a text file first.txt and write some text to it. Create another text file second.txt which contains the reverse of the content of the first.txt file.

21. WAP to demonstrate the concept of fread() and fwrite() operation for structures.