SHOW:
|
|
- or go back to the newest paste.
1 | - | // Test.cpp : Defines the entry point for the console application. |
1 | + | // CTest.cpp : Defines the entry point for the console application. |
2 | // | |
3 | ||
4 | - | #include "stdafx.h" |
4 | + | |
5 | - | #include <stdio.h> |
5 | + | |
6 | - | #include <string.h> |
6 | + | |
7 | - | #define NUM_WORDS 10 |
7 | + | #include <stdio.h> |
8 | - | #define LENGTH 20 |
8 | + | #include <string.h> |
9 | #define NUM_WORDS 10 | |
10 | #define LENGTH 20 | |
11 | ||
12 | - | int _tmain(int argc, _TCHAR* argv[]) |
12 | + | void sort(char words[][LENGTH], int num) |
13 | { | |
14 | - | char array[NUM_WORDS][LENGTH]; |
14 | + | |
15 | int i; | |
16 | - | int i; |
16 | + | |
17 | int j; | |
18 | - | int j; |
18 | + | |
19 | char temp[LENGTH]; | |
20 | - | int counter = 0; |
20 | + | |
21 | for ( i = 0 ; i < num - 1 ; i++ ) | |
22 | - | for ( i = 0 ; i < NUM_WORDS ; i++ ) |
22 | + | { |
23 | ||
24 | for ( j = i + 1 ; j < num ; j++ ) | |
25 | - | printf("Enter a word: "); |
25 | + | |
26 | ||
27 | - | scanf("%s", array[i]); |
27 | + | |
28 | - | counter++; |
28 | + | if ( strcmp(words[i], words[j]) > 0 ) |
29 | - | if ( array[i][0] == '0' ) |
29 | + | |
30 | ||
31 | - | |
31 | + | strcpy(temp, words[i]); |
32 | - | break; |
32 | + | |
33 | strcpy(words[i], words[j]); | |
34 | - | |
34 | + | |
35 | strcpy(words[j], temp); | |
36 | } | |
37 | - | //sort(array, NUM_WORDS); |
37 | + | |
38 | } | |
39 | - | printf("\nYour sorted list is: "); |
39 | + | } |
40 | } | |
41 | - | for ( j = 0 ; j < counter ; j++ ) |
41 | + | |
42 | int main(void) | |
43 | { | |
44 | - | printf("%s ", array[j]); |
44 | + | char array[NUM_WORDS][LENGTH]; |
45 | ||
46 | int i; | |
47 | - | printf("\n"); |
47 | + | int j; |
48 | int num = 0; | |
49 | - | return 0; |
49 | + | |
50 | for ( i = 0 ; i < NUM_WORDS ; i++ ) | |
51 | { | |
52 | ||
53 | printf("Enter a word: "); | |
54 | ||
55 | scanf("%s", array[i]); | |
56 | ||
57 | if ( array[i][0] == '0' ) | |
58 | break; | |
59 | num++; | |
60 | ||
61 | } | |
62 | ||
63 | sort(array, num); | |
64 | ||
65 | printf("\nYour sorted list is: "); | |
66 | ||
67 | for ( j = 0 ; j < num ; j++ ) | |
68 | { | |
69 | ||
70 | printf("%s ", array[j]); | |
71 | } | |
72 | ||
73 | printf("\n"); | |
74 | ||
75 | return 0; | |
76 | ||
77 | } |