Question

Write a simple C/C++ function named int match_content(char * file1, char *file2) that would take two...

Write a simple C/C++ function named int match_content(char * file1, char *file2) that would take two text file name as a parameter, and return 1, if the content is same in both the files, 0 otherwise. Your program should be case insensitive and should support all the ascii characters.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

int match_content(char * file1, char *file2) {
    FILE *f1 = fopen(file1, "r");
    FILE *f2 = fopen(file2, "r");
    if (f1 && f2) {
        char c1, c2;
        while ((c1 = (char)getc(f1)) != EOF && (c2 = (char)getc(f2)) != EOF) {
            if (c1 >= 'a' && c1 <= 'z') {
                c1 -= 32;
            }
            if (c2 >= 'a' && c2 <= 'z') {
                c2 -= 32;
            }
            if (c1 != c2) {
                return 0;
            }
        }
        return getc(f1) == EOF and getc(f2) == EOF;
    }
    return 0;
}

int main() {
    printf("%d\n", match_content("input1.txt", "input2.txt"));
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
Write a simple C/C++ function named int match_content(char * file1, char *file2) that would take two...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a simple C/C++ function, void copy_create(char * file), that would take one text file name...

    Write a simple C/C++ function, void copy_create(char * file), that would take one text file name as parameter and create a file named “duplicate.txt”, having the content of the file name sent as parameter.

  • you need to write a C function named rem. The prototype is: int rem(char*, char*); The...

    you need to write a C function named rem. The prototype is: int rem(char*, char*); The function accepts 2 strings: the first is a string of text to process; the second is where the output will be placed. rem() should remove all occurrences of a lowercase 'x' from the first string, and save the resulting string in the second arg. You may use the strlen() function; no other built-in fuctions should be used. Test your program thoroughly. Then, once you...

  • a. Ask the user for the input of a letter (char type). Write a function that...

    a. Ask the user for the input of a letter (char type). Write a function that takes a char as the argument (parameter) and returns the ASCII value of that char back to the caller. Call the function using the char variable and taking input from the user (no validation required). Display the value in ASCII. b. Write a program that takes a char as the argument (parameter) and uses a loop to interrogate the char, calling a function that...

  • ​Write a C++ function int calculate(char, int , int ) which takes a char of either ‘+’, ‘ ‘--’, ‘*’, or ‘/’ as operator and two integers as operands.

    Write a C++ function int calculate(char, int , int ) which takes a char of either ‘+’, ‘ ‘--’, ‘*’, or ‘/’ as operator and two integers as operands. The function should return the result of applying the corresponding operator on the operands if all of them are of proper types and values. It should throw a char exception if the operator is unknown and a char* exception if the operator is ‘/’ and the second operand is zero. Write...

  • 1.) Write a recursive function named isPalindrome that will take a single string as an argument...

    1.) Write a recursive function named isPalindrome that will take a single string as an argument and determine if the argument is a palindrome. The function must return True if the argument is a palindrome, False otherwise. Recall that any string is a palindrome if its first and last characters are the same and the rest of it is also a palindrome (therefore, a single character is a palindrome): 2.) Consider a text file named samplestrings.txt that contains a collection...

  • This assignment uses functions, files, and strings. Enough flexibility is provided for you to apply your...

    This assignment uses functions, files, and strings. Enough flexibility is provided for you to apply your knowledge of basic C++ programing to develop your solution. Develop a functional flowchart and then write a C++ program to solve the following problem. 1. Create a text file named file1.txt and write your brand of car (like Honda, Toyota, etc) in the file. You will be reading the name of the file from the keyboard as a string, using the string class. Your...

  • Write a function named insertBeforeKey that takes the parameters as follows list as an char array,...

    Write a function named insertBeforeKey that takes the parameters as follows list as an char array, capacity for the capacity of the array, numItems has the number of items in the array, key is an element of the array before which newVal is to inserted. Assume key is always present in the array. and newVal has the new value to be inserted into the array. If the array is at capacity then the function should return -1, otherwise return 0...

  • Please convert this C function into ARM ASSEMBLY LANGUAGE CORTEX M (Must be cortex m) #include<...

    Please convert this C function into ARM ASSEMBLY LANGUAGE CORTEX M (Must be cortex m) #include<stdio.h> int ascii(char c) {                 return (int)c; } int computeMagicNumber(char* name) {                 int sum, i; //varibales                 sum = 0; //set sum to 0                 //calculate sum                 int N = sizeof(name)/sizeof(name[0]); //get name size                 for(i=0;i<N;i++)                                 sum = sum + (i+1)*ascii(name[i]);                                 return sum%1001; //return magic number MAIN FUNCTION : extern int computeMagicNumber(char *); int main(void) { char name[255]="Yusuf Ozturk"; int magic; magic=computeMagicNumber(name); printf("\n Magic number is %d\n",magic); return...

  • write program in C language. To get more practice working with files, you will write several...

    write program in C language. To get more practice working with files, you will write several functions that involve operations on files. In particular, implement the following functions 1. Write a function that, given a file path/name as a string opens the file and returns its entire contents as a single string. Any endline characters should be preserved char *getFileContents (const char filePath); 2. Write a function that, given a file path/name as a string opens the file and returns...

  • Create a C project named login_l06t1. Write and test a function strnclean that takes two strings...

    Create a C project named login_l06t1. Write and test a function strnclean that takes two strings as parameters, target and source. Using the ctype library, copy only the alphabetic characters from source to target, and make the characters lower case. Ex: source: David Brown! target: davidbrown Prototype: void strnclean(char *target, const char *source); How do i do this using the C type library below! int isalnum(int c) Returns non-zero (true) if c is an alphanumeric character, zero otherwise. int isalpha(int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT