Starting Vocational Training From 1-May-2024 Get Detail


C language

File Handling
1.

Write a program in C to copy a file in another name. 

Assume that the content of the file test.txt is :                                                                       
test line 1                                                                                                   
test line 2                                                                                                   
test line 3                                                                                                   
test line 4                                                                                                   

Test Data :
Input the source file name : test.txt
Input the new file name : test1.txt
Expected Output :

The file test.txt  copied successfully in the file test1.txt.

If you read the new file you will see the content of the file :

test line 1                                                                                                   
test line 2                                                                                                   
test line 3                                                                                                   
test line 4

Solution
2.

Write a program in C to delete a specific line from a file. 

Assume that the content of the file test.txt is :                                                                       
test line 1                                                                                                   
test line 2                                                                                                   
test line 3                                                                                                   
test line 4                                                                                                   

Test Data :
Input the file name to be opened : test.txt
Input the line you want to remove : 2
Expected Output :

 The content of the file test.txt is :                                                                       
test line 1                                                                                                   
test line 3                                                                                                   
test line 4

Solution
3.

Write a program in C to count a number of words and characters in a file. 

Test Data :
Input the file name to be opened : test.txt
Expected Output :

 The content of the file test.txt are :                                                                       
test line 1                                                                                                   
test line 2                                                                                                   
test line 3                                                                                                   
test line 4                                                                                                   
 The number of words in the  file test.txt are : 12                                                           
 The number of characters in the  file test.txt are : 36

Solution
4.

Write a program in C to read the file and store the lines into an array. 
Test Data :
Input the file name to be opened : test.txt
Expected Output :

 The content of the file test.txt  are :                                                                      
 test line 1                                                                                                  
 test line 2                                                                                                  
 test line 3                                                                                                  
 test line 4

Solution
5.

Write a program in C to read an existing file. 
Test Data :
Input the file name to be opened : test.txt
Expected Output :

 The content of the file test.txt is  :                                                                       
This is the content of the file test.txt.

Solution
6.

Write a program in C to create and store information in a text file.
Test Data :
Input a sentence for the file : This is the content of the file test.txt.
Expected Output :

 The file test.txt created successfully...!! 

Solution