Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // CTest.cpp : Defines the entry point for the console application.
- //
- #include <stdio.h>
- #include <string.h>
- #define NUM_WORDS 10
- #define LENGTH 20
- void sort(char words[][LENGTH], int num)
- {
- int i;
- int j;
- char temp[LENGTH];
- for ( i = 0 ; i < num - 1 ; i++ )
- {
- for ( j = i + 1 ; j < num ; j++ )
- {
- if ( strcmp(words[i], words[j]) > 0 )
- {
- strcpy(temp, words[i]);
- strcpy(words[i], words[j]);
- strcpy(words[j], temp);
- }
- }
- }
- }
- int main(void)
- {
- char array[NUM_WORDS][LENGTH];
- int i;
- int j;
- int num = 0;
- for ( i = 0 ; i < NUM_WORDS ; i++ )
- {
- printf("Enter a word: ");
- scanf("%s", array[i]);
- if ( array[i][0] == '0' )
- break;
- num++;
- }
- sort(array, num);
- printf("\nYour sorted list is: ");
- for ( j = 0 ; j < num ; j++ )
- {
- printf("%s ", array[j]);
- }
- printf("\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement