SlideShare a Scribd company logo
1 of 6
PROGRAMMING FOR PROBLEM SOLVING
TOPIC: APPENDING DATA TO EXISTING FILES
NAME:- ANUSHA ASHRAF
H.NO:- 23L51A7205
ROLL.NO:- 05
BRANCH:- AI&DS
A File handing in C is the process in which
we create, open, read, write, and close
operations on a file.
C language provides different functions
such as fopen(), fwrite(), fread(), fseek(),
fprintf(), etc. to perform input, output, and
many different C file operations in our
program.
FILE HANDLING
APPENDING DATA TO EXISTING
FILE
Appending data in C programming means
adding new data to the end of an existing
file without overwriting the existing data.
This is useful when you want to add new
data to a file without losing the old data. To
append data to a file in C programming, you
can use the fopen() function with
the "a" mode flag.
C PROGRAM USING
APPENDING DATA TO
EXISTING FILE
 The program opens the given
file and asks the user to enter
the data to append to the file
and successfully appends it to
the existing file. It also gives a
feedback on the success of the
operation.

#include <stdio.h>
int main()
{
FILE *fp;
char data[100];
fp = fopen(“anusha.c”, “a”);
printf(“Enter data to append:n”);
fgets(data, sizeof(data), stdin);
fprintf(fp, “%s”, data);
printf(“Data appended successfullyn”);
fclose(fp);
return 0;
}
Output:-
Enter data to append:
Good
Data appended successfully
PROGRAM EXPLANATION
#include <stdio.h>
int main()
{
FILE *fp;
char data[100];
fp = fopen(“anusha.c”, “a”);
printf(“Enter data to append:n”);
fgets(data, sizeof(data), stdin);
fprintf(fp, “%s”, data);
printf(“Data appended successfullyn”);
fclose(fp);
return 0;
}
Output:-
Enter data to append:
Good
Data appended successfully
1.Header Inclusion:
•The program includes the standard input/output library (<stdio.h>) for
input/output operations.
2.Variable Declaration:
•FILE *fp;: Declares a pointer to a file (FILE) named fp.
•char data[100];: Declares an array named data to store user input.
3.File Opening:
•fp = fopen(“anusha.c", "a");: Opens the file named “anusha.c" in append mode
("a"). The file is opened for writing, and if it does not exist, it will be created.
4.User Input:
•printf("Enter data to append:n");: Prompts the user to enter data.
•fgets(data, sizeof(data), stdin);: Uses fgets to get input from the user, including
spaces. The entered data is stored in the data array.
5.Data Appending:
•fprintf(fp, "%s", data);: Appends the data stored in the data array to the file
using fprintf.
6.Output Confirmation:
•printf("Data appended successfullyn");: Informs the user that the data has
been appended successfully.
7.File Closing:
•fclose(fp);: Closes the file.
8.Return Statement:
•return 0;: Indicates successful execution of the program.
This program allows the user to enter data, appends it to the "file.txt" file, and provides
feedback on the success of the operation.
THANK YOU

More Related Content

Similar to APPENEDING OF DATA TO AN EXISTING FILES.

C UNIT-5 PREPARED BY M V BRAHMANANDA REDDY
C UNIT-5 PREPARED BY M V BRAHMANANDA REDDYC UNIT-5 PREPARED BY M V BRAHMANANDA REDDY
C UNIT-5 PREPARED BY M V BRAHMANANDA REDDY
Rajeshkumar Reddy
 
Chapter 13.1.10
Chapter 13.1.10Chapter 13.1.10
Chapter 13.1.10
patcha535
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
Kumar
 

Similar to APPENEDING OF DATA TO AN EXISTING FILES. (20)

Unit 8
Unit 8Unit 8
Unit 8
 
File handling With Solve Programs
File handling With Solve ProgramsFile handling With Solve Programs
File handling With Solve Programs
 
file_handling_in_c.ppt
file_handling_in_c.pptfile_handling_in_c.ppt
file_handling_in_c.ppt
 
file_handling_in_c.ppt
file_handling_in_c.pptfile_handling_in_c.ppt
file_handling_in_c.ppt
 
Lecture 20 - File Handling
Lecture 20 - File HandlingLecture 20 - File Handling
Lecture 20 - File Handling
 
File in C language
File in C languageFile in C language
File in C language
 
Module 03 File Handling in C
Module 03 File Handling in CModule 03 File Handling in C
Module 03 File Handling in C
 
Satz1
Satz1Satz1
Satz1
 
File operations in c
File operations in cFile operations in c
File operations in c
 
Introduction of file handling
Introduction of file handlingIntroduction of file handling
Introduction of file handling
 
Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)
 
Module 5 file cp
Module 5 file cpModule 5 file cp
Module 5 file cp
 
File handling-c
File handling-cFile handling-c
File handling-c
 
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdfEASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
 
C UNIT-5 PREPARED BY M V BRAHMANANDA REDDY
C UNIT-5 PREPARED BY M V BRAHMANANDA REDDYC UNIT-5 PREPARED BY M V BRAHMANANDA REDDY
C UNIT-5 PREPARED BY M V BRAHMANANDA REDDY
 
Php advance
Php advancePhp advance
Php advance
 
Chapter 13.1.10
Chapter 13.1.10Chapter 13.1.10
Chapter 13.1.10
 
File handling in C++
File handling in C++File handling in C++
File handling in C++
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
 
working with files
working with filesworking with files
working with files
 

Recently uploaded

electrical installation and maintenance.
electrical installation and maintenance.electrical installation and maintenance.
electrical installation and maintenance.
benjamincojr
 

Recently uploaded (20)

The Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptxThe Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptx
 
Passive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.pptPassive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.ppt
 
analog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxanalog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptx
 
Linux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message QueuesLinux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message Queues
 
Raashid final report on Embedded Systems
Raashid final report on Embedded SystemsRaashid final report on Embedded Systems
Raashid final report on Embedded Systems
 
Interfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdfInterfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdf
 
Multivibrator and its types defination and usges.pptx
Multivibrator and its types defination and usges.pptxMultivibrator and its types defination and usges.pptx
Multivibrator and its types defination and usges.pptx
 
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptxSLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
 
Operating System chapter 9 (Virtual Memory)
Operating System chapter 9 (Virtual Memory)Operating System chapter 9 (Virtual Memory)
Operating System chapter 9 (Virtual Memory)
 
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdfInstruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
 
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTUUNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
 
electrical installation and maintenance.
electrical installation and maintenance.electrical installation and maintenance.
electrical installation and maintenance.
 
"United Nations Park" Site Visit Report.
"United Nations Park" Site  Visit Report."United Nations Park" Site  Visit Report.
"United Nations Park" Site Visit Report.
 
Geometric constructions Engineering Drawing.pdf
Geometric constructions Engineering Drawing.pdfGeometric constructions Engineering Drawing.pdf
Geometric constructions Engineering Drawing.pdf
 
Dynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxDynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptx
 
Vip ℂall Girls Karkardooma Phone No 9999965857 High Profile ℂall Girl Delhi N...
Vip ℂall Girls Karkardooma Phone No 9999965857 High Profile ℂall Girl Delhi N...Vip ℂall Girls Karkardooma Phone No 9999965857 High Profile ℂall Girl Delhi N...
Vip ℂall Girls Karkardooma Phone No 9999965857 High Profile ℂall Girl Delhi N...
 
5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptx
 
Insurance management system project report.pdf
Insurance management system project report.pdfInsurance management system project report.pdf
Insurance management system project report.pdf
 
Introduction to Artificial Intelligence and History of AI
Introduction to Artificial Intelligence and History of AIIntroduction to Artificial Intelligence and History of AI
Introduction to Artificial Intelligence and History of AI
 

APPENEDING OF DATA TO AN EXISTING FILES.

  • 1. PROGRAMMING FOR PROBLEM SOLVING TOPIC: APPENDING DATA TO EXISTING FILES NAME:- ANUSHA ASHRAF H.NO:- 23L51A7205 ROLL.NO:- 05 BRANCH:- AI&DS
  • 2. A File handing in C is the process in which we create, open, read, write, and close operations on a file. C language provides different functions such as fopen(), fwrite(), fread(), fseek(), fprintf(), etc. to perform input, output, and many different C file operations in our program. FILE HANDLING
  • 3. APPENDING DATA TO EXISTING FILE Appending data in C programming means adding new data to the end of an existing file without overwriting the existing data. This is useful when you want to add new data to a file without losing the old data. To append data to a file in C programming, you can use the fopen() function with the "a" mode flag.
  • 4. C PROGRAM USING APPENDING DATA TO EXISTING FILE  The program opens the given file and asks the user to enter the data to append to the file and successfully appends it to the existing file. It also gives a feedback on the success of the operation.  #include <stdio.h> int main() { FILE *fp; char data[100]; fp = fopen(“anusha.c”, “a”); printf(“Enter data to append:n”); fgets(data, sizeof(data), stdin); fprintf(fp, “%s”, data); printf(“Data appended successfullyn”); fclose(fp); return 0; } Output:- Enter data to append: Good Data appended successfully
  • 5. PROGRAM EXPLANATION #include <stdio.h> int main() { FILE *fp; char data[100]; fp = fopen(“anusha.c”, “a”); printf(“Enter data to append:n”); fgets(data, sizeof(data), stdin); fprintf(fp, “%s”, data); printf(“Data appended successfullyn”); fclose(fp); return 0; } Output:- Enter data to append: Good Data appended successfully 1.Header Inclusion: •The program includes the standard input/output library (<stdio.h>) for input/output operations. 2.Variable Declaration: •FILE *fp;: Declares a pointer to a file (FILE) named fp. •char data[100];: Declares an array named data to store user input. 3.File Opening: •fp = fopen(“anusha.c", "a");: Opens the file named “anusha.c" in append mode ("a"). The file is opened for writing, and if it does not exist, it will be created. 4.User Input: •printf("Enter data to append:n");: Prompts the user to enter data. •fgets(data, sizeof(data), stdin);: Uses fgets to get input from the user, including spaces. The entered data is stored in the data array. 5.Data Appending: •fprintf(fp, "%s", data);: Appends the data stored in the data array to the file using fprintf. 6.Output Confirmation: •printf("Data appended successfullyn");: Informs the user that the data has been appended successfully. 7.File Closing: •fclose(fp);: Closes the file. 8.Return Statement: •return 0;: Indicates successful execution of the program. This program allows the user to enter data, appends it to the "file.txt" file, and provides feedback on the success of the operation.