English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Write a C program that compares two files and issues the message
file1 and file2 are identical
when the files are the same or issues the message
file1 and file2 : first difference in byte number ___.
when they are different. The names of the two files should appear as command line parameters.

2006-11-19 15:17:50 · 2 answers · asked by Shaina B 1 in Computers & Internet Programming & Design

2 answers

Come up with an algorithms, test it, then code it, then debug it. Something like...

1)Get names of files
2)open files
3)compare all data in files
4)if same do this
5)if different do this

2006-11-19 15:35:27 · answer #1 · answered by D 4 · 0 0

What compiler and what working technique? ANSI C has a function technique(char *) in stdlib.h (which you will get right of entry to in c++ by utilising using #which incorporates cstlib. It takes as a controversy an ASCIIZ string (0 deliminated char array) which you will assemble on the fly utilising sstreams. for DOS of direction you may use duplicate file1 file2 or bypass file1 file2 for the string (i'm an historic c programmer) for Unix or GNU/Linux you may use cp file1 file1 or mv file1 file2 yet on a similar time as the latter of direction is in the comparable itemizing then it quite is the comparable simply by fact of certainty the dos ren command. to employ command line arguments in a C or C++ utility then basically do a: int significant(int argc char *argv) { and argc retail shops the quantity of command line arguments so attempt to look no count in spite of if it relatively is not as much as 3. if so obstacle an errors message and bypass out. If now not, argv[0] is the p.c.. out of the utility you're strolling. argv[a million] ought to be file1 in the above social amassing. argv[2] ought to be file2 in the above examples. and of direction you will use fstreams to do the swap.

2016-10-22 09:44:07 · answer #2 · answered by Anonymous · 0 0

fedest.com, questions and answers