Question: For this task, you will implement the primary data structure as a 1-dimensional string array char * Strings[NUM], where NUM is the number of strings,
For this task, you will implement the primary data structure as a 1-dimensional string array char * Strings[NUM], where NUM is the number of strings, and the length of strings will be determined dynamically.
Using the starter file assign4/task4/bubble.c, implement bubble sort of strings in dictionary order. Your code must strictly follow these specifications:
-
Use fgets() to read each string from the input, one string per line. Use LEN as an argument to fgets() to ensure that an input line that is too long does not exceed the bounds imposed by the string's length.
-
Note that LEN is the size of buffer fgets() uses. Each string in the array Strings must not waste space, that is, if a line is only abc, then the storage for this string in the array Strings should be 4 bytes instead of LEN.
-
Note that the newline and NULL characters will be included in LEN, so the maximum number of printable characters in the string will actually be LEN-2.
-
The comparison of two strings must be done by checking them one character at a time, without using any C string library functions. That is, write your own loop or implement your own mystrcmp() to do this.
-
The swap of two strings must be done by swapping two pointers, no copying of chars are allowed. Write your own swap function to do this (How would the prototype of swap-two-pointers look like?).
-
You are allowed to use C library functions for printing strings, e.g., fputs(), puts(), printf(), etc.
-
You are allowed to use the C library function strlen() to calculate the length of a string.
-
No other string libraries/functions are allowed. [you can use malloc/free from stdlib.h]
Compile and run your program on inputs of your choice, and you can use < and > to redirect the input of your choice and output if you would like your code to read inputs from a file instead of from the keyboard.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
