This document discusses file input/output (I/O) operations in C. It covers key concepts like what a file is, common file operations, opening and closing files, reading and writing to files, using buffers, and different file opening modes. It also discusses reading/writing characters, strings, and records to files. Functions covered include fopen(), fclose(), fgetc(), fputs(), fread(), fwrite(), fseek(), and rewind(). The document provides examples of copying a file, reading/writing structured records to binary files, and implementing basic database operations using file I/O functions.
File Operation such as
Reading the file content
Writing the content to the file
Copying the content from one file to another file
Counting the number of character, words and lines of the file
C Programming Language is the most popular computer language and most used programming language till now. It is very simple and elegant language. This lecture series will give you basic concepts of structured programming language with C.
Text Input / Output: Files, Streams, Standard Library Input / Output Functions, Formatting Input / Output Functions, Character Input / Output Functions, Binary Input / Output: Text versus Binary Streams, Standard Library, Functions for Files, Converting File Type
File Operation such as
Reading the file content
Writing the content to the file
Copying the content from one file to another file
Counting the number of character, words and lines of the file
C Programming Language is the most popular computer language and most used programming language till now. It is very simple and elegant language. This lecture series will give you basic concepts of structured programming language with C.
Text Input / Output: Files, Streams, Standard Library Input / Output Functions, Formatting Input / Output Functions, Character Input / Output Functions, Binary Input / Output: Text versus Binary Streams, Standard Library, Functions for Files, Converting File Type
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Dr. Vinod Kumar Kanvaria
Exploiting Artificial Intelligence for Empowering Researchers and Faculty,
International FDP on Fundamentals of Research in Social Sciences
at Integral University, Lucknow, 06.06.2024
By Dr. Vinod Kumar Kanvaria
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
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.
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
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.
2. WHAT IS A FILE?
A file is a collection of related data that a
computers treats as a single unit.
Computers store files to secondary storage so
that the contents of files remain intact when a
computer shuts down.
When a computer reads a file, it copies the file
from the storage device to memory; when it
writes to a file, it transfers data from memory to
the storage device.
3. FILE OPERATIONS
Creation of a new file
Opening of existing file
Reading from a file
Writing to a file
Moving to a specific location in a file
Closing a file
4. OPENING A FILE
Before we can read or write information on a
disk we must open a file.
To open a file, the function is fopen().
fopen() performs three important tasks:
Firstly, it searches on the disk the file to be
opened.
Then it loads the file from the disk into the place
in memory called buffer.
It sets up a character pointer that points to the
first character of the buffer.
5. NEED OF BUFFERS
It is inefficient to access the disk every time we
want to read a character from it.
Similarly instead of writing characters in a file
on disk one character at a time it would be more
efficient to write a characters in a buffer and then
finally transfer the contents from the buffer to
the disk.
6. USE OF *FP
To successfully read from a file information like mode of
opening, size of file, place in file from where the next read
operation would be performed has to be maintained.
All of this is gathered by fopen() in a structure called
FILE.fopen() returns the address of this structure, which is
collected in structure pointer called fp.
FILE *fp;
Th e FILE structure is defined in header file “stdio.h”
7. READING FROM A FILE
To read a file’s content from memory, there
exists a function called fgetc()
In this the end of file is a special character whose
ASCII value as 26,signifies the end of file.
When file encounters this special character it
returns the macro EOF. The EOF is defined in
stdio.h
8. TROUBLE IN OPENING A FILE
While using fopen, if we are not able to open the file in
“r” mode, this is because the file being opened may not
be present on the disk.
If we are opening the file for writing, fopen() may fail
due to a number of reasons, like, disk space may be
insufficient to open a new file, or the disk may be write
protected or the disk is damaged and so on.
So,it is important for any program that accesses disk files
to check whether a file has been opened successfully
before trying to read or write to the file.
9. CONT…
If the file opening fails due to any of the several reasons
mentioned above, the fopen( ) function returns a value
NULL (defined in “stdio.h” as #define NULL 0).
if ( fp == NULL )
{
puts ( "cannot open file" ) ;
exit(1) ;
}
10. CLOSING THE FILE
When we have finished reading from the file, we need to
close it. This is done using the function fclose( ) through
the statement:
fclose ( fp ) ;
Once we close the file we can no longer read from it
using getc( ) unless we reopen the file. Note that to close
the file we don’t use the filename but the file pointer fp.
On closing the file the buffer associated with the file is
removed from memory.
11. CLOSING THE FILE
When we open a file to write characters into it. This time too a
buffer would get associated with it. When we attempt to write
characters into this file using fputc( ) the characters would get
written to the buffer. When we close this file using fclose( )
three operations would be performed:
The characters in the buffer would be written to the file on the
disk.
At the end of file a character with ASCII value 26 would get
written.
The buffer would be eliminated from memory.
What if the buffer may become full before we close the
file?
13. A FILE-COPY PROGRAM
fputc( )- writes characters to a file.
main( )
{
FILE *fs, *ft ;
char ch ;
fs = fopen ( "pr1.c", "r" ) ;
if ( fs == NULL )
{
puts ( "Cannot open source file" ) ;
exit( ) ;
}
ft = fopen ( "pr2.c", "w" ) ;
14. if ( ft == NULL )
{
puts ( "Cannot open target file" ) ;
fclose ( fs ) ;
exit( ) ;
}
while ( 1 )
{
ch = fgetc ( fs ) ;
if ( ch == EOF )
break ;
else
fputc ( ch, ft ) ;
}
fclose ( fs ) ;
fclose ( ft ) ;
}
15. WRITING TO A FILE
The fputc( ) function is similar to the putch( ) function,
in the sense that both output characters.
putch( ) function always writes to the VDU, whereas,
fputc( ) writes to the file. The file is signified by ft.
The writing process continues till all characters from the
source file have been written to the target file, following
which the while loop terminates.
This file-copy program is capable of copying only text
files.
16. FILE OPENING MODES
Following is a list of all possible modes in which a file can be
opened.
"r"
Operations possible – reading from the file.
"w"
Operations possible – writing to the file.
"r+"
Operations possible - reading existing contents, writing
new contents, modifying existing contents of the file.
17. "a"
Operations possible - adding new contents at the end of file.
"w+"
Operations possible - writing new contents, reading them
back and modifying existing contents of the file.
"a+"
Operations possible - reading existing contents, appending
new contents to end of file. Cannot modify existing contents.
18. STRING (LINE) I/O IN FILES
The usage of functions that read or write entire strings
might turn out to be more efficient.
We can write strings to a file using the function fputs( ).
while ( strlen ( gets ( s ) ) > 0 )
{
fputs ( s, fp ) ;
fputs ( "n", fp ) ;
}
fclose ( fp ) ;
}
19. CONT…
Each string is terminated by hitting enter. To terminate
the execution of the program, hit enter at the beginning
of a line. This creates a string of zero length, which the
program recognizes as the signal to close the file and
exit.
Since fputs( ) does not automatically add a newline
character to the end of the string, we must do this
explicitly to make it easier to read the string back from
the file.
20. READ STRINGS FROM THE FILE
while ( fgets ( s, 79, fp ) != NULL )
printf ( "%s" , s ) ;
fgets( ) takes three arguments.
The first is the address where the string is stored,
Second is the maximum length of the string. This argument
prevents fgets( ) from reading in too long a string and
overflowing the array.
The third argument, as usual, is the pointer to the structure
FILE.
When all the lines from the file have been read, we attempt to
read one more line, in which case fgets( ) returns a NULL.
21. THE AWKWARD NEWLINE
When we attempt to write a “n” to the file using fputs( ),
fputs( ) converts the n to rn combination. Here r stands
for carriage return and n for linefeed.
If we read the same line back using fgets( ) the reverse
conversion happens.
Thus conversion of n to rn during writing and rn
conversion to n during reading is a feature of the standard
library functions and not that of the OS. Hence the OS
counts r and n as separate characters.
22. RECORD I/O IN FILES
So far we have dealt with reading and writing only characters and
strings. What if we want to read or write numbers from/to file?
To read/write a combination of characters, strings and numbers we
would organize this dissimilar data together in a structure and then
use fprintf( ) and fscanf( ) library functions to read/write data
from/to file.
main( )
{
FILE *fp ;
char another = 'Y' ;
struct emp
{
char name[40] ;
int age ;
float bs ;
} ;
23. struct emp e ;
fp = fopen ( "EMPLOYEE.DAT", "w" ) ;
if ( fp == NULL )
{
puts ( "Cannot open file" ) ;
exit(1) ;
}
while ( another == 'Y' )
{
printf ( "nEnter name, age and basic salary: " ) ;
scanf ( "%s %d %f", e.name, &e.age, &e.bs ) ;
fprintf ( fp, "%s %d %fn", e.name, e.age, e.bs ) ;
printf ( "Add another record (Y/N) " ) ;
fflush ( stdin ) ;
another = getche( ) ;
}
fclose ( fp ) ;
24. FFLUSH( )
After supplying data for one employee, we would hit the
enter key. What scanf( ) does is it assigns name, age and
salary to appropriate variables and keeps the enter key
unread in the keyboard buffer.
When it’s time to supply Y or N for the question
‘Another employee (Y/N)’, getch( ) will read the enter
key from the buffer thinking that user has entered the
enter key.
To avoid this problem we use the function fflush( ). It is
designed to remove or ‘flush out’ any data remaining in
the buffer.
The argument to fflush( ) must be the buffer which we
want to flush out. Here we have used ‘stdin’, which
means buffer related with standard input device—
keyboard.
26. TEXT VERSUS BINARY MODE: NEWLINES
If a file is opened in binary mode, as opposed to
text mode, the following conversions will not
take place:
A newline character to the carriage return-
linefeed combination before being written to the
disk.
Likewise, the carriage return-linefeed
combination on the disk is converted back into a
newline
27. TEXT VERSUS BINARY MODE: END OF FILE
The second difference between text and binary modes is in
the way the end-of-file is detected. In text mode, a special
character, whose ASCII value is 26, is inserted after the
last character in the file to mark the end of file.
There is no such special character present in the binary
mode files to mark the end of file. The binary mode files
keep track of the end of file from the number of characters
present in the directory entry of the file.
28. CONT…
If a file stores numbers in binary mode, it is important
that binary mode only be used for reading the numbers
back, since one of the numbers we store might well be
the number 26 (hexadecimal 1A). If this number is
detected while we are reading the file by opening it in
text mode, reading would be terminated prematurely at
that point.
Thus the two modes are not compatible.
29. TEXT VERSUS BINARY MODE: STORAGE OF
NUMBERS
In case of text mode the only function that is available
for storing numbers in a disk file is the fprintf( )
function.
Text and characters are stored one character per byte.
Numbers are stored as strings of characters. Thus, 1234,
even though it occupies two bytes in memory, when
transferred to the disk using fprintf( ), would occupy four
bytes, one byte per character.
30. CONT…
Hence if large amount of numerical data is to be stored in
a disk file, using text mode may turn out to be inefficient.
The solution is to open the file in binary mode and use
the functions fread( ) and fwrite( ). It means each number
would occupy same number of bytes on disk as it
occupies in memory.
31. RECORD I/O REVISITED
The record I/O program has two disadvantages:
The numbers would occupy more number of bytes, since
the file has been opened in text mode.
If the number of fields in the structure increase, writing
structures using fprintf( ), or reading them using fscanf(
), becomes quite clumsy.
32. Write records to the Binary file
main( )
{
FILE *fp ;
char another = 'Y' ;
struct emp
{
char name[40] ;
int age ;
float bs ;
} ;
struct emp e ;
fp = fopen ( "EMP.DAT", "wb" ) ;
if ( fp == NULL )
{
puts ( "Cannot open file" ) ;
exit( ) ;
}
33. while ( another == 'Y' )
{
printf ( "nEnter name, age and basic salary: " ) ;
scanf ( "%s %d %f", e.name, &e.age, &e.bs ) ;
fwrite ( &e, sizeof ( e ), 1, fp ) ;
printf ( "Add another record (Y/N) " ) ;
fflush ( stdin ) ;
another = getche( ) ;
}
fclose ( fp ) ;
}
34. Reading records from binary file
main( )
{
FILE *fp ;
struct emp
{
char name[40] ;
int age ;
float bs ;
} ;
struct emp e ;
fp = fopen ( "EMP.DAT", "rb" ) ;
35. if ( fp == NULL )
{
puts ( "Cannot open file" ) ;
exit( ) ;
}
while ( fread ( &e, sizeof ( e ), 1, fp ) == 1 )
printf ( "n%s %d %f", e.name, e.age, e.bs ) ;
fclose ( fp ) ;
}
The function fread( ) returns the number of
records read. Ordinarily, this should correspond
to the third argument, the number of records
36. DATABASE MANAGEMENT
There is a provision to Add, Modify, List and Delete
records, the operations that are imperative in any
database management. Following comments would help
in understanding the program easily:
Addition of records must always take place at the end of
existing records in the file.
Listing records means displaying the existing records on
the screen. Naturally, records should be listed from first
record to last record.
While modifying records, first we must ask the user
which record he intends to modify. Instead of asking the
record
37. In deleting records, except for the record to be deleted,
rest of the records must first be written to a temporary
file, then the original file must be deleted, and the
temporary file must be renamed back to original.
Note that the file is being opened only once and closed
only once, which is quite logical.
38. PROGRAM FOR DATABASE MANAGEMENT
A pointer is initiated whenever we open a file. On
opening a file a pointer is set up which points to the first
record in the file.
On using the functions fread( ) or fwrite( ), the pointer
moves to the beginning of the next record.
On closing a file the pointer is deactivated.
Note that the pointer movement is of utmost importance
since fread( ) reads that record where the pointer is
currently placed. Similarly, fwrite( ) writes the record
where the pointer is currently placed.
39. CONT…
The rewind( ) function places the pointer to the
beginning of the file, irrespective of where it is present
right now.
The fseek( ) function lets us move the pointer from one
record to another. To move the pointer to the previous
record from its current position, we used the function:
fseek ( fp, -recsize, SEEK_CUR ) ;
The following fseek( ) would place the pointer beyond
the last record in the file.
fseek ( fp, 0, SEEK_END ) ;
-recsize or 0 are just the offsets that tell the compiler by
how many bytes should the pointer be moved from a
particular position.
40. CONT…
The third argument of fseek function could be
SEEK_END, SEEK_CUR or SEEK_SET- these are
macro defined in “stdio.h”.
SEEK_END means move the pointer from the end of
the file.
SEEK_CUR means move the pointer with reference to
its current position.
SEEK_SET means move the pointer with reference to
the beginning of the file.
If we want to know where the pointer is positioned right
now, we can use the function ftell( ).
position = ftell ( fp ) ;
where position is a long int.