FoCP Lab Manual 13
FoCP Lab Manual 13
CLO-3 Demonstrate the ability to independently understand and solve a problem using
programming techniques and apply the acquired knowledge to challenging tasks.
CLO-4 Use the latest IDEs and other supplementary tools to aid code implementation, testing, and
management as per standard practices in the software industry.
BSCS-13E
Time: 14:30 -17:00
Date: 22-12-2023
Course Instructor’s: Dr. Naseer Bajwa
Lab Engineer: Engr. Masabah Bint E Islam
Evaluation Rubric
Application of The student is unable to apply The student requires some The student demonstrates a
1
Programming guidance to apply the clear ability to apply the
Concepts the appropriate programming appropriate programming appropriate programming
concepts to solve the given concepts to solve the given concepts to solve the given
(CLO 2, PLO 3)
problem. The program flow problem. The program flow
problem thus resulting in an diagrams and pseudocodes diagrams and pseudocodes
incomplete or ineffective require minor are adequate. The code has
improvements. The code sufficient comments and
solution. The program flow has limited comments and consistent variable names
diagrams and pseudocodes inconsistent variable names and reasonably adheres to
and may not adhere to the the coding standards.
are missing or coding standards.
incomprehension. The code
has inadequate comments
and variable names and does
not adhere to the coding
standards.
The student did
Software tool The student has no idea The student has a limited The student has full
2 not submit any
usage how to use the basic tools command on various tools
word OR The command of the basic tools
of the software. The codes available in the software.
(CLO 3, PLO4) student
have syntax errors, and of the software. The codes Furthermore, his/her coding
plagiarized the
parts of the coding are is complete and functional,
solution and/or are correct in terms of their
missing. Codes are and the program output is
used unfair
nonmodular and cannot be syntax; however, the program correct. Codes are modular,
means.
reused. reusable, and easily
output is not always correct. readable.
Codes are semi-modular and
semi-reusable.
Individual and The student disturbs the The student cooperates with In addition to performing
3
Teamwork (ClO- lab environment. Distracts other group members in a well individually and in a
4, PLO-5) or discourages other reasonable manner. Performs team, also provided
group members from well individually and in a leadership in the team.
conducting the team. Actively engages and
experiments. Can’t cooperates with other group
perform well both members in an effective
individually and as part of manner.
a team.
Introduction to Experiments
In this fundamental of computer programming lab manual, we explore the
file handling in C.
Tools/Software Required
• IDE for C Language
1. fopen()
The fopen function is used to open a file.
#include <stdio.h>
int main() {
FILE *fp;
// Open file for writing
fp = fopen("example.txt", "w");
if (fp == NULL) {
perror("Error opening file");
return -1;
}
// Write to the file
fprintf(fp, "Hello, world!\n");
// Close the file
fclose(fp);
return 0;
}
In this example, a file named "example.txt" is opened for writing. If the file opening is successful, "Hello, world!" is
written to the file. After writing, the file is closed using fclose. Remember to always check if fopen returns NULL,
as this indicates an error in opening the file (such as the file not existing or lacking the necessary permissions).
Please refer to course slides for more information.
Lab Tasks
Description:
Description:
1. Open 'File1' in read mode and 'File2' in read and write mode.
2. Read the contents of 'File1'.
3. Read the contents of 'File2' and temporarily store them.
4. Write the contents of 'File1' to 'File2', then append the original contents of 'File2'.
5. Close both files.
Steps:
Deliverables:
Submit a single file on LMS before the due date in PDF format as communicated by lab engineer.
Note: Use proper indentation and comments. Lack of comments and indentation will result in
deduction of marks. You will submit your working codes and outputs (Just Screenshots).