Question: Answer this programming problem using C language with comments Part B: Finding fingerprint groups In this problem you are to write a program fgroups (short

Answer this programming problem using C language with comments
Answer this programming problem using C language with comments Part B: Finding
fingerprint groups In this problem you are to write a program fgroups
(short for fingerprint groups"), which when given a set of names with

Part B: Finding fingerprint groups In this problem you are to write a program fgroups (short for fingerprint groups"), which when given a set of names with fingerprints will identify groups of names that share a fingerprint. The real object of the exercise is to familiarize you with the CII library and with CI/O. Your input is always on standard input. Input is a sequence of lines where each line has the following format: The line begins with one or more non-whitespace characters. This sequence of characters is the fingerprint. The fingerprint is followed by one or more whitespace characters, not including newline. The name begins with the next non-whitespace character and continues through the next newline. A name may contain whitespace, but a name never contains a newline. Finally, you may also assume that each name appears at most once. You may assume that a fingerprint is at most 512 characters long (2048 bits represented in hexadecimal notation), but there is no a priori upper bound on the length of a name. What to do with good input By the nature of the input, every fingerprint you read will be associated with at least one name. If a fingerprint is associated with exactly one name, ignore the fingerprint (and the name). . If a fingerprint is associated with two or more names, those names consti- tute a fingerprint group. A fingerprint group always has at least two members. Your program should print all the fingerprint groups in the following format: If there are no fingerprint groups, print nothing. If there is exactly one fingerprint group, print it. If there are multiple fingerprint groups, print them separated by newlines. Groups may be printed in any order. To print a fingerprint group, print each name in the group. Put a newline after each name, as if by printf("%s ", name); Names within the group may be printed in any order. For example, if the input is A Ron Poppy B Bill A Dubya B Barry Orange B Joe Then one possible output is Ron Dubya Poppy Orange Bill Barry Joe (This example output contains exactly one blank line.) My solution to this problem takes about 150 lines of C code. About 25 lines deal with input: about 25 lines are devoted to printing output; and about 50 lines are memory management and I/O. The actual algorithm is under 20 lines. The rest is comments, whitespace, #include directives, and the like. What to do with bad input . If you get an input line that is badly formed write an error message to stderr, discard the badly formed line, and continue. . If you get a fingerprint of more than 512 characters, you may choose to write an error message to stderr, discard the line, and contime or you may handle the oversize fingerprint correctly. In other words, your program doesn't need to handle fingerprints larger than 512 characters, but you won't be penalized if it does. Your program should handle any name that can appear in the filesystem; if you get a name that is longer than you can handle, write a suitable message to stderr, truncate the name, and use the truncated name with the given fingerprint . If a name appears more than once, your program may silently give wrong answers, but it must not crash or commit memory errors. Problem analysis and advice This problem boils down to simple string processing and standard data structures. . C strings are different from C++ strings, and C's string library is nearly useless. You've got two sensible choices: - Roll your own string processing using pointer arithmetic and the standard header file . - Use either the Str or the Text interface from C Interfaces and Im- plementations. . When it comes to string comparison, what you know is wrong. In C, writing if (s1 -- s2) {...} does not compare equality of two strings it compares equality of pointers. To compare two strings for equality, you must write if (strncmp(s1, s2) == 0) {...} Many experts choose to write this code more briefly: if (!strcmp(s1, s2)) {...} but the briefer style requires a sharp eye for the exclamation mark. Hanson's Atom interface maps equal strings to identical pointers, so pointer equality is OK on strings created with Atom_string or Atom_new. To use strings with Hanson's data structures, you must use the Atom interface. Hanson provides sets, finite maps, and a wealth of sequence abstractions. Any or all of these may be useful for solving the fingerprint problem. Your job is to figure out what data structures will be useful and how to combine them into a clean design. Repeat: the data structures are already built for you; your job is to figure out which ones will be useful

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!