Question
Asked by:
$1.50 write a program to produce alphabeticall
- From Engineering: Computer-Engineering
- Closed, but you can still post tutorials
- Due on Mar. 03, 2009
- Asked on Mar 02, 2009 at 2:26:52PM
Q:write a program to produce alphabetically sort 10 words entered by a user in to an array.
Develope a swap function
-take two argument str1 and str2
-swap the argumentif the string pointed to by str2 is earlier in the alphabetthan str1
-return 1 if a swap was made,otherwise returnig 0.
HINT 1
If p is a pointer to a character, and n is the amount of storage you wish to allocate, then use the statement
p=malloc(n*sizeof(char));
HINT2
Use the function strcmp,which is defined in string.h to detrmine the relative position of two strings in the alphabet.
HINT3
Declare an array containing 10 string pointers (called str_array)
for (10 items)
read string from the keyboard
daynamically allocate space and store string in str_array
do repeatedly for each string i in str_array
call the swap function with str_array[i+1] as argument
Increment the number_of_swaps variable if a swap occured
end the loop until the number_of_swaps is zero
Display the sorted strings on the screen



