#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int areTheyEqual(FILE *fp1, FILE *fp2)
{
//getting characters in two files in two char variables a and
b
char a=getc(fp1);
char b=getc(fp2);
//running loop until atleast one of them reaches end of file
while(a!=EOF && b!=EOF)
{
if(a!=b) return 0;//if two characters at any time are not equal
returning 0
//again giving new values to a and b
a=getc(fp1);
b=getc(fp2);
}
//if one variable reaches end of line and other doesnot then the
two files are not equal
if(a!=EOF &&b!=EOF) return 0;
//if it came here then the two files are equal so returning 1
return 1;
}
int main() {
//we shall open files in read only format
FILE *fp1 = fopen("first.txt", "r");
FILE *fp2 = fopen("second.txt", "r");
//checking if any pointers are NULL
if (fp1 == NULL || fp2 == NULL)
{
printf("files did not opened");
exit(0);
}
//if the function returns 1 then they are equal else they are not
equal
if(areTheyEqual(fp1,fp2)) printf("they are equal\n");
else printf("they are not equal\n");
//closing the two files
fclose(fp1);
fclose(fp2);
return 0;
}
if you are satisfied please upvote or if you have any doubts post them in comment section happy learning
Write a c program CH-12 TEXT FILES EXERCISE 12-12 Write a program to read two files of the same length, and determine if they are equal. For example: if one of the file has the content 123 abc 45...
Write c program. Do part 4 and 5 CH-12 TEXT FILES SE 12-3 Create a text file named grade.txt that you type yourself by your Each record in grade.txt should have the following format: by Columns 1-4 6-8 number of a student A grade out of 100 EYERCISE 12-4 Write a program that will read the identification numbers of students and their letter grades (A, B, C, D, or F) from the keyboard and store them in a text file...
Write a c program. CH-12 has arbitrary number of lines and one num. txt EXERCISE 12-11 te a program to create a new file numnew. txt that will he ine. A text file will have number in reverse order of the file num.txt For example: M the num.txt file is 7632 582 13101 then the numnew. txt file will be 1367 285 10131 CH-12 has arbitrary number of lines and one num. txt EXERCISE 12-11 te a program to create...
Write a python program that prompts the user for the names of two text files and compare the contents of the two files to see if they are the same. If they are, the scripts should simply output “Yes”. If they are not, the program should output “No”, followed by the first lines of each file that differ from each other. The input loop should read and compare lines from each file. The loop should break as soon as a...
4.3Learning Objective: To read and write text files. Instructions: This is complete program with one Java source code file named H01_43.java (your main class is named H01_43). Problem: Write a program that prompts the user for the name of a Java source code file (you may assume the file contains Java source code and has a .java filename extension; we will not test your program on non-Java source code files). The program shall read the source code file and output...
Write a C++ program that reads text from a file and encrypts the file by adding 6 to the ASCII value of each character. See section 5.11 in Starting out with C++ for information on reading and writing to text files. Your program should: 1. Read the provided plain.txt file one line at a time. Because this file has spaces, use getline (see section 3.8). 2. Change each character of the string by adding 6 to it. 3. Write the...
Write a C program which is called ‘multiple_copy’. This program copies one source file to two destination files as follows: $./multiple_copy....... source_file....... destination_file1......... destination_file2 multiple_copy program copies the contents of source file (i.e., source_file) to any named two destination files in the command line. The number of arguments should be 4 including multiple_copy. If the number of arguments is not 4, the program should display error message saying: “Usage: multiple_copy source_file destination_file1 destination_file2”. When the source_file does not exist, the...
3. Write a program to read a (binary) file of integers, sort the integers, and write them back to the same file. Assume that all the numbers can be stored in an array. (Exercise 3) 4. Repeat exercise 3, but assume that only 20 numbers can be stored in memory (in an array) at any one time. Hint: you will need to use at least two additional files for temporary output. Please finish the question in C language programming, thank...
C++ please Write a program that reads the following sentences from a file: I am Sam Sam I am That Sam I am That Sam I am I do not like that Sam I am Do you like green eggs and ham I do not like them But I do like spam! You will first have to create the text file containing the input, separate from your program. Your program should produce two output files: (i) (ii) one with the...
Lab #10 C++ Write a C++ program that reads text from a file and encrypts the file by adding an encryption factor (EF) to the ASCII value of each character. The encryption factor is 1 for the first line and increases by 1 for each line up to 4 and then starts over at 1. So, for the 4 th line the EF is 4, for the 5th line it is 1, for the 10th line it is 2. In...
(Java) Rewrite the following exercise below to read inputs from a file and write the output of your program in a text file. Ask the user to enter the input filename. Use try-catch when reading the file. Ask the user to enter a text file name to write the output in it. You may use the try-with-resources syntax. An example to get an idea but you need to have your own design: try ( // Create input files Scanner input...