The document discusses various file handling functions in C like fseek(), ftell(), rewind(), fgets(), fputs(), fflush(), rename(), remove(), freopen(), ferror(), fgetpos(), fsetpos() and command line arguments. Some key functions covered are:
- fseek() moves the file position indicator within a file.
- ftell() returns the current file position indicator.
- rewind() resets the file position indicator to the beginning of the file.
- fgets() and fputs() reads/writes strings to a file stream.
- rename() changes the name of a file. remove() deletes a file.
- freopen() redirects file streams like
This was the fifth and last presentation in pySIG, 2015 @ BMS College of Engineering, Bangalore. The code and assignments can be found at https://github.com/pranavsb
Python too supports file handling and allows users to handle files i.e., to read and write files, along with many other file handling options, to operate on files. The concept of file handling has stretched over various other languages, but the implementation is either complicated or lengthy, but alike other concepts of Python, this concept here is also easy and short. Python treats file differently as text or binary and this is important. Each line of code includes a sequence of characters and they form text file. Each line of a file is terminated with a special character, called the EOL or End of Line characters like comma {,} or newline character. It ends the current line and tells the interpreter a new one has begun. Let’s start with Reading and Writing files.
This was the fifth and last presentation in pySIG, 2015 @ BMS College of Engineering, Bangalore. The code and assignments can be found at https://github.com/pranavsb
Python too supports file handling and allows users to handle files i.e., to read and write files, along with many other file handling options, to operate on files. The concept of file handling has stretched over various other languages, but the implementation is either complicated or lengthy, but alike other concepts of Python, this concept here is also easy and short. Python treats file differently as text or binary and this is important. Each line of code includes a sequence of characters and they form text file. Each line of a file is terminated with a special character, called the EOL or End of Line characters like comma {,} or newline character. It ends the current line and tells the interpreter a new one has begun. Let’s start with Reading and Writing files.
** Python Certification Training: https://www.edureka.co/python **
This Edureka PPT on File Handling with Python covers all the important aspects of using files in Python right from the introduction to what fields are, all the way till checking out the major aspects of working with files and using the code-first approach to understand them better.
Python Tutorial Playlist: https://goo.gl/WsBpKe
Blog Series: http://bit.ly/2sqmP4s
Follow us to never miss an update in the future.
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
Concept of file, Opening and closing of file, Modes, Input/ output function, Random access in file, Printing a file
A file represents a sequence of bytes on the disk where a group of related data is stored. File is created for permanent storage of data. It is a ready made structure.
In C language, we use a structure pointer of file type to declare a file.....
h2kinfosys is offering the IT Online Courses with Certificates ,H2kinfosys is the best place to learn online coding classes as we offer the most job oriented training led by experienced instructors through live classroom sessions. It courses online from h2kinfosys . top trending courses like learn tableau online, hadoop certification Training, python certification online and more courses register for free demo class .
https://www.h2kinfosys.com/
** Python Certification Training: https://www.edureka.co/python **
This Edureka PPT on File Handling with Python covers all the important aspects of using files in Python right from the introduction to what fields are, all the way till checking out the major aspects of working with files and using the code-first approach to understand them better.
Python Tutorial Playlist: https://goo.gl/WsBpKe
Blog Series: http://bit.ly/2sqmP4s
Follow us to never miss an update in the future.
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
Concept of file, Opening and closing of file, Modes, Input/ output function, Random access in file, Printing a file
A file represents a sequence of bytes on the disk where a group of related data is stored. File is created for permanent storage of data. It is a ready made structure.
In C language, we use a structure pointer of file type to declare a file.....
h2kinfosys is offering the IT Online Courses with Certificates ,H2kinfosys is the best place to learn online coding classes as we offer the most job oriented training led by experienced instructors through live classroom sessions. It courses online from h2kinfosys . top trending courses like learn tableau online, hadoop certification Training, python certification online and more courses register for free demo class .
https://www.h2kinfosys.com/
At the end of this lecture students should be able to;
Define the C standard functions for managing file input output.
Apply taught concepts for writing programs.
Delivering Micro-Credentials in Technical and Vocational Education and TrainingAG2 Design
Explore how micro-credentials are transforming Technical and Vocational Education and Training (TVET) with this comprehensive slide deck. Discover what micro-credentials are, their importance in TVET, the advantages they offer, and the insights from industry experts. Additionally, learn about the top software applications available for creating and managing micro-credentials. This presentation also includes valuable resources and a discussion on the future of these specialised certifications.
For more detailed information on delivering micro-credentials in TVET, visit this https://tvettrainer.com/delivering-micro-credentials-in-tvet/
Safalta Digital marketing institute in Noida, provide complete applications that encompass a huge range of virtual advertising and marketing additives, which includes search engine optimization, virtual communication advertising, pay-per-click on marketing, content material advertising, internet analytics, and greater. These university courses are designed for students who possess a comprehensive understanding of virtual marketing strategies and attributes.Safalta Digital Marketing Institute in Noida is a first choice for young individuals or students who are looking to start their careers in the field of digital advertising. The institute gives specialized courses designed and certification.
for beginners, providing thorough training in areas such as SEO, digital communication marketing, and PPC training in Noida. After finishing the program, students receive the certifications recognised by top different universitie, setting a strong foundation for a successful career in digital marketing.
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...Levi Shapiro
Letter from the Congress of the United States regarding Anti-Semitism sent June 3rd to MIT President Sally Kornbluth, MIT Corp Chair, Mark Gorenberg
Dear Dr. Kornbluth and Mr. Gorenberg,
The US House of Representatives is deeply concerned by ongoing and pervasive acts of antisemitic
harassment and intimidation at the Massachusetts Institute of Technology (MIT). Failing to act decisively to ensure a safe learning environment for all students would be a grave dereliction of your responsibilities as President of MIT and Chair of the MIT Corporation.
This Congress will not stand idly by and allow an environment hostile to Jewish students to persist. The House believes that your institution is in violation of Title VI of the Civil Rights Act, and the inability or
unwillingness to rectify this violation through action requires accountability.
Postsecondary education is a unique opportunity for students to learn and have their ideas and beliefs challenged. However, universities receiving hundreds of millions of federal funds annually have denied
students that opportunity and have been hijacked to become venues for the promotion of terrorism, antisemitic harassment and intimidation, unlawful encampments, and in some cases, assaults and riots.
The House of Representatives will not countenance the use of federal funds to indoctrinate students into hateful, antisemitic, anti-American supporters of terrorism. Investigations into campus antisemitism by the Committee on Education and the Workforce and the Committee on Ways and Means have been expanded into a Congress-wide probe across all relevant jurisdictions to address this national crisis. The undersigned Committees will conduct oversight into the use of federal funds at MIT and its learning environment under authorities granted to each Committee.
• The Committee on Education and the Workforce has been investigating your institution since December 7, 2023. The Committee has broad jurisdiction over postsecondary education, including its compliance with Title VI of the Civil Rights Act, campus safety concerns over disruptions to the learning environment, and the awarding of federal student aid under the Higher Education Act.
• The Committee on Oversight and Accountability is investigating the sources of funding and other support flowing to groups espousing pro-Hamas propaganda and engaged in antisemitic harassment and intimidation of students. The Committee on Oversight and Accountability is the principal oversight committee of the US House of Representatives and has broad authority to investigate “any matter” at “any time” under House Rule X.
• The Committee on Ways and Means has been investigating several universities since November 15, 2023, when the Committee held a hearing entitled From Ivory Towers to Dark Corners: Investigating the Nexus Between Antisemitism, Tax-Exempt Universities, and Terror Financing. The Committee followed the hearing with letters to those institutions on January 10, 202
A workshop hosted by the South African Journal of Science aimed at postgraduate students and early career researchers with little or no experience in writing and publishing journal articles.
The simplified electron and muon model, Oscillating Spacetime: The Foundation...RitikBhardwaj56
Discover the Simplified Electron and Muon Model: A New Wave-Based Approach to Understanding Particles delves into a groundbreaking theory that presents electrons and muons as rotating soliton waves within oscillating spacetime. Geared towards students, researchers, and science buffs, this book breaks down complex ideas into simple explanations. It covers topics such as electron waves, temporal dynamics, and the implications of this model on particle physics. With clear illustrations and easy-to-follow explanations, readers will gain a new outlook on the universe's fundamental nature.
This slide is special for master students (MIBS & MIFB) in UUM. Also useful for readers who are interested in the topic of contemporary Islamic banking.
This presentation includes basic of PCOS their pathology and treatment and also Ayurveda correlation of PCOS and Ayurvedic line of treatment mentioned in classics.
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
Pride Month Slides 2024 David Douglas School District
File handling(some slides only)
1. RANDOM ACCESS TO FILES
• So far we have seen file functions that are useful for
read and write data sequentially.
• However, sometime we require to access only a
particular part of a file.
• This can be achieved using fseek , ftell and rewind
function available in I/O library.
1
2. ftell
• ftell takes a file pointer fp and return a number of type
long, that corresponds to the current position.
Example: n = ftell(fp);
• n would give the relative offset (in bytes) of the current
position. This means that n bytes have already been read
(or written).
2
3. fseek
• fseek function is used to move the file position to a desired location
within the file. It takes the following form:
fseek(file_ptr, offset, position);
• file_ptr is a pointer to the file concerned.
• offset is a number or variable of type long
• position is an integer number
• The offset specifies the number of positions (bytes) to be moved
from the location specified by position.
• The position can take one of the following three values:
Value Meaning
0 Beginning of file
1 Current position
2 End of file
3
4. • When the operation is successful, fseek returns a
zero.
• If we attempt to move the file pointer beyond the
file boundaries, an error occurs and fseek returns -1
(minus one).
4
5. rewind
• Rewind takes a file pointer and resets the position to the
start of the file.
rewind(fp);
n = ftell(fp);
• Above two line code would assign 0 to n because the file
position has been set to the start of the file by rewind.
5
6. • Remember, the first byte in the file is numbered
as 0, second as 1, and so on.
• Remember that whenever a file is opened for
reading or writing, a rewind is done implicitly.
6
7. Statement Meaning
fseek(fp,0L,0) Go to the beginning.(Similar to rewind).
fseek(fp,0L,1) Stay at the current position(Rarely used).
fseek(fp,0L,2) Go to the end of the file, past the last character of
the file.
fseek(fp,m,0) Move to (m+1)th byte in the file
fseek(fp,m,1) Go forward by m bytes
fseek(fp,-m,1) Go backward by m bytes from the current position.
fseek(fp,-m,2) Go backward by m bytes from the end.(Position
the file to the mth character from the end.)
7
8. Write a program that uses the functions ftell and fseek.
#include <stdio.h>
void main()
{ FILE *fp;
long n;
char c;
fp = fopen("RANDOM", "w");
while((c = getchar()) != EOF)
putc(c,fp);
printf("No. of characters entered = %ldn", ftell(fp));
fclose(fp);
fp = fopen("RANDOM","r");
8
n = 0L;
9. while(feof(fp) == 0)
{
fseek(fp, n, 0); /* Position to (n+1)th character */
printf("Position of %c is %ldn", getc(fp),ftell(fp));
n = n+5L;
}
putchar('n');
fseek(fp,-1L,2); /* Position to the last character */
do
{
putchar(getc(fp));
}
while(!fseek(fp,-2L,1));
fclose(fp);
}
9
10. Output:
ABCDEFGHIJKLMNOPQRSTUVWXYZ^Z
No. of characters entered = 26
Position of A is 0
Position of F is 5
Position of K is 10
Position of P is 15
Position of U is 20
Position of Z is 25
Position of is 30
ZYXWVUTSRQPONMLKJIHGFEDCBA
10
11. fgets
• Reads count - 1 characters from the given file stream and
stores them in str.
• Characters are read until either a newline or an EOF is
received or until the specified limit is reached.
• Declaration:
char *fgets( char *str, int count, FILE *stream );
• Returns str on success or a NULL pointer on failure.
11
12. • Example of fgets:
#include <stdio.h> sample.txt
#include <stdlib.h> This is first line.
This is second line and longer than first line. The
End.
void main()
{
FILE *fp;
char str[128];
fp = fopen(“sample.txt", “r”);
fgets(str, 126, fp);
printf("%s", str); Output:
fclose(fp); This is first line.
} Note: Only first line displayed because new
line occurred. 12
13. fputs
• fputs writes text string to the stream. The string's null
terminator is not written.
• Declaration: int fputs(const char *str, FILE *stream);
• Returns nonnegative on success and EOF on failure.
• Example of fputs:
void main()
{
FILE *fp;
fp = fopen(“test.txt", "w”);
fputs(“This is written to test file.", fp);
fclose(fp);
}
13
14. fflush
• fflush empties the file io buffer and causes the
contents to be written into the file immediately.
• The buffer is a block of memory used to temporarily
store data before actually writing it onto the disk.
• The data is only actually written to the file when the
buffer is full, the file stream is closed or when
fflush() is called.
• The fflush function returns zero if successful or EOF
if an error was encountered.
14
15. rename
• The function rename changes the name of the
file oldfilename to newfilename.
• Declaration:
int rename(const char *old_filename, const char *new_filename )
• It returns 0 upon success and non-zero value on error.
• Example of rename:
#include <stdio.h>
void main()
{
int renameFile = 0;
renameFile = rename("MYFILE.txt", "HELLO.txt");
if (renameFile != 0)
printf("Error in renaming file.");
getch();
} 15
16. remove
• Deletes the file whose name is specified in filename.
• Declaration: int remove ( const char * filename )
• 0 is returned if file is successfully deleted and a nonzero value
is returned on failure.
#include <stdio.h>
#include <conio.h>
void main ()
{
if ( remove("myfile.txt”) != 0 )
printf( "Error deleting file" );
else
printf( "File successfully deleted" );
getch();
}
16
17. freopen
• freopen() is used to redirect the system-defined files stdin,
stdout and stderr to some other file.
• Header file: stdio.h
• Declaration: freopen(“filename”, “mode”, stream);
• It Returns a pointer to stream on success or a null pointer
on failure.
17
18. • Example of freopen:
#include <stdio.h>
#include <conio.h>
void main()
{
FILE *fp;
printf("This will display on the screen.n");
if((fp = freopen(“test.txt", "w" ,stdout)) == NULL)
{
printf("Cannot open file.n");
}
printf("This will be written to the file OUT.");
fclose(fp);
} 18
19. ferror
• ferror checks for a file error.
• Header File: stdio.h
• Declaration: int ferror(FILE *stream);
• It returns 0 if no error has occurred and nonzero integer if
an error has occurred.
• ferror example:
19
21. fgetpos and fsetpos
• fgetpos gets the file position indicator.
• fsetpos moves the file position indicator to a specific
location in a file.
• Declaration: int fgetpos(FILE *stream, fpos_t *pos)
– stream: A pointer to a file stream.
– pos: A pointer to a file position.
• They returns zero on success and nonzero on failure
21
22. • Example of fgetpos and fsetpos:
#include <stdio.h>
void main ()
{
FILE *fp;
fpos_t position;
fp = fopen (“test.txt","w");
fgetpos (fp, &position);
fputs (“I like BCA", fp);
fsetpos (fp, &position);
fputs (“We“,fp);
fclose (fp);
} 22
23. Command line arguments
• What is a command line argument?
It is a parameter supplied to a program when the program
is invoked.
• main can take two arguments called argc and argv and the
information contained in the command line is passed on to
the program through these arguments, when main is called
up by the system.
main(int argc , char *argv[])
• The variable argc is an argument counter that counts the
number of arguments on the command line.
• The argv is an argument vector and represents an array of
character pointers that point to the command line
arguments. 23
24. • Write a program that will receive a filename and a line of text as
command line arguments and write the text to the file.
• Explaination of programme:
• Command line is:
cmdl test AAAAAA BBBBBB CCCCCC DDDDDD EEEEEE FFFFFF GGGGGG
• Each word in the command line is an argument to the main and
therefore the total number of arguments is 9.
• The argument vector argv[1] points to the string test and therefore
the statement fp = fopen(argv[1], "w"); opens a file with the name
test.
• The for loop that follows immediately writes the remaining 7
arguments to the file test.
24
25. #include <stdio.h>
void main(argc, argv)
int argc; /* argument count */
char *argv[]; /* list of arguments */
{
FILE *fp;
int i;
char word[15];
fp = fopen(argv[1], "w"); /* open file with name argv[1] */
printf("nNo. of arguments in Command line = %dnn", argc);
for(i = 2; i < argc; i++)
fprintf(fp,"%s ", argv[i]); /* write to file argv[1] */
fclose(fp);
25
26. /* Writing content of the file to screen */
printf("Contents of %s filenn", argv[1]);
fp = fopen(argv[1], "r");
for(i = 2; i < argc; i++)
{
fscanf(fp,"%s", word);
printf("%s ", word);
}
fclose(fp);
printf("nn");
/* Writing the arguments from memory */
for(i = 0; i < argc; i++)
printf("%*s n", i*5,argv[i]);
} 26
27. Output:
C:> cmdl test AAAAAA BBBBBB CCCCCC DDDDDD EEEEEE FFFFFF GGGGG
No. of arguments in Command line = 9
Contents of test file
AAAAAA BBBBBB CCCCCC DDDDDD EEEEEE FFFFFF GGGGGG
C:>cmdl.EXE //This is argv[0]
TEXT //This is argv[1]
AAAAAA //This is argv[2]
BBBBBB
CCCCCC
DDDDDD
EEEEEE
FFFFFF
GGGGGG 27