@Nameless One
5781 / 3430 / 255
Регистрация: 08.02.2010
Сообщений: 7,448
|
04.01.2011, 10:25
|
|
C | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 256
#define DELIMS ",.\n"
int main()
{
char buf[SIZE];
char* pword;
char words[30][6];
size_t cnt;
size_t i;
puts("Input string:");
fgets(buf, SIZE, stdin);
memset(words, '\0', 30 * 6 * sizeof(char));
for(pword = strtok(buf, DELIMS), cnt = 0;
pword; pword = strtok(NULL, DELIMS), ++cnt)
strncpy(words[cnt], pword, 5);
qsort(words, cnt, sizeof(char[6]),
(int (*) (const void*, const void*)) strcmp);
puts("Sorted words:");
for(i = 0; i < cnt; ++i)
printf("%02u: \"%s\"\n", i + 1, words[i]);
exit(0);
} |
|
1
|