IGPIGP
Комп_Оратор)
6935 / 3218 / 320
Регистрация: 04.12.2011
Сообщений: 8,885
|
31.01.2014, 17:50
|
|
Так бы можно еще:
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
33
34
35
36
37
38
39
40
41
42
43
44
| #include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
int main()
{
char str[50], str_origin[50], *z;
gets(str_origin);
strcpy(str,str_origin);
z=strtok(str," ");
int words_count=0;
while(z!=NULL){
z=strtok(NULL," ");
words_count++;
}
cout<<endl;
char **mas=(char**)calloc(words_count, sizeof(char*));
strcpy(str,str_origin);//восстановили строку после strtok
z=strtok(str," ");
int cnt=0;
char* tmp=0;
while(z!=NULL){
tmp=z;
mas[cnt] = (char*)calloc(strlen(z)+1, sizeof(char));
strcpy(mas[cnt],z);
z=strtok(NULL," ");
cnt++;
}
for(int i=0;i<words_count;i++)
puts(&mas[i][0]);
cout<<endl;
system("pause");
return 0;
} |
|
2
|