File Processing: Beec 1313 Programming Fundamental
File Processing: Beec 1313 Programming Fundamental
normal .txt files Binary files are mostly the .bin files in your
can be easily create using Notepad or any computer.
simple text editors.
Instead of storing data in plain text, they
When open those files, all the contents store it in the binary form (0's and 1's).
within the file can be seen as plain text. You
can easily edit or delete the contents. They can hold higher amount of data, are
They take minimum effort to maintain, are not readable easily and provides a better
easily readable, and provide least security security than text files.
and takes bigger storage space.
FILE OPERATIONS
r Open for reading. If the file does not exist, fopen() returns NULL.
rb Open for reading in binary mode. If the file does not exist, fopen() returns NULL.
r+ Open for both reading and writing. If the file does not exist, fopen() returns NULL.
Open for both reading and writing If the file exists, its contents are overwritten. If the file
wb+
in binary mode. does not exist, it will be created.
int main(){
Complete the given code in order char modifieddata[40] = "";
to: char c;
FILE *fp;
Read texts from message.txt
fp = fopen(“????","r");
Convert all uppercase if (fp == NULL){
lowercase printf("Error in opening file!\n");
Convert all lowercase exit(1);
uppercase }
int i=0;
Display modified string
??????
int main(){ do {
char modifieddata[40] = ""; c = fgetc(fp);
char c; if (isupper(c))
FILE *fp; c = tolower(c);
fp = fopen("message.txt","r"); else if (islower(c))
if (fp == NULL){ c = toupper(c);
printf("Error in opening file!\n"); modifieddata[i] = c;
exit(1); i++;
} } while (!(feof(fp)));
int i=0; printf("modified text = %s \n", modifieddata);
fclose (fp);
return 0;
}
WRITING TO A FILE