Question
Asked by:
Amantes
Amantes
Rating : No Rating
Questions Asked: 6
Tutorials Posted: 0
 

$1.50 write a program to produce alphabeticall

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
 


   
   
   
   
 
Available Tutorials to this Question
Posted by:
rainman
rainman
Rating (40): A+
Questions Asked: 2
Tutorials Posted: 174, earned $906.64
 

$5.00 C Program To Alphabetically Sort User Inputed Words. Does Everything Asked

  • This tutorial was purchased 1 time and hasn't been rated yet.
  • Posted on Mar 03, 2009 at 2:16:41PM
A:
Preview: ... n()<br>{<br> //Declare an array of 10 char*<br> char *str_array[10];<br><br> //temporary buffer to hold the c string<br> char buffer[128];<br><br> //for the sorting<br> int number_of_swaps = 1;<br><br> //for the loop iteration<br> int i;<br><br> //length of user input<br> int length;<br><br> printf("Please enter 10 words to be alphabetically sorted.\\\\n\\\\n");<br><br> //A loop so the user can enter 10 words<br> for (i = 0; i < 10; i++)<br> ...

The full tutorial is about 491 words long plus attachments.

Attachments:
main.c (2K) (Preview)
   
Join Now or Log In
Get Tutoring
Get Paid
Academic Honesty