,   CyberForum.ru

, - C++


 
C++ ++ http://www.cyberforum.ru/cpp-beginners/thread634673.html
. ++ . " C++ 21 " ...
C++ ! , , char, char * string. ? //char text="";//tak ne poidet //char *text="";//tak toje ne... http://www.cyberforum.ru/cpp-beginners/thread634669.html
C++
. . #include<iostream> #include<windows.h> using namespace std; float a, b, c,...
C++
xx/xx/xxxx ? / 01 1 'x' ... #include <iostream> using namespace std; struct...
C++ http://www.cyberforum.ru/cpp-beginners/thread634621.html
. , ? : #include<windows.h> #include <iostream> using...
C++ , : char name; unsigned long size; GetUserName(name,&size); CopyFile("C:\\Users\\!!!\\AppData\\Local\\Google\\Chrome\\User...

-==-
 FAQ
08.08.2012, 17:52
bullin2d
, .
bullin2d,
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
int getNumWordsInSentence(char * sentence);
 
int main()
{
    int nWords        = 0;//áóäåò õð**èòü ÷èñëî ñëîâ
    int nSentence     = 0;//áóäåò õð**èòü ÷èñëî ïðåäëîæå*èé
 
    char inp[1024]    = {0};//Áóôôåð äëÿ ââîäèìîãî òåêñò*
    char out[1024]    = {0};//Áóôôåð äëÿ âûâîäèìîãî òåêñò*
    char sentence[128]= {0};//Áóôôåð äëÿ ïåðäëîæå*èÿ
    char * sub        = NULL;//Óê*ç*òåëü ** ïîäñòðîêó ñ ïðåäëîæå*èåì
    //Âîçìîæ*ûå ð*çäåëèòåëè ìåæäó ïðåäëîæå*èÿìè
    char **sWords     = NULL;//Óê*çåòåëü ** ì*ññèâ ñ ïðåäëîæå*èÿìè èç òåêñò*
    char delim[] = ".!?";
    //Ââîäèì òåêñò
    printf("Enter text   : ");scanf("%[^\n]",inp);
    printf("Enter nWords : ");scanf("%d",&nWords);
/*  strcpy
    (
        inp,
        "hello. world is nice. cool day! to be or not to be? very nice day!"
    );
    nWords = 3;*/
    strcpy(out,inp);
    //Ïîäñ÷¸ò ÷èñë* ïðåäëîæå*èé â òåêñòå
    for
    (
        sub = strtok( out,delim);
        sub != NULL;
        sub = strtok(NULL,delim)
    )
        nSentence = nSentence + 1;
    //Âûäåëÿåì ï*ìÿòü ïîä ñòðîêè ì*ññèâ* ïðåäëîæå*èé
    sWords = (char **)malloc(nSentence*sizeof(char *));
    //Êîïèðóåì ïðåäëîæå*èÿ â ì*ññèâ
    nSentence = 0;
    out[0]    = 0;
    for
    (
        sub = strtok( inp,delim);
        sub != NULL;
        sub = strtok(NULL,delim)
    )
    {
        sWords[nSentence] = (char *)malloc(128*sizeof(char *));
        strcpy(sWords[nSentence],sub);
        nSentence = nSentence + 1;
    }
    //Îñò*âëåÿì â âûõîä*îì òåêñòå *óæ*ûå ïðåäëîæå*èÿ
    while(nSentence)
    {
        strcpy(sentence,sWords[nSentence - 1]);
        if(nWords == getNumWordsInSentence(sentence))
        {
            if(!out[0])
                strcpy(out,sWords[nSentence - 1]);
            else
                strcat(out,sWords[nSentence - 1]);
        }
        nSentence = nSentence - 1;
    }
    printf("Output text : %s\n",out);
    return 0;
}
 
int getNumWordsInSentence(char * sentence)
{
    int nCount  = 0;  //×èñëî ñëîâ â ïðåäëîæå*èè
    char *word  = {0};//Óê*ç*åòëü ** ñëîâî èç òåêñò*
    //Âîçìîæ*ûå ð*çäåëèòåëè ìåæäó ñëîâ*ìè
    char delim[] = ",;:- ";
    for
    (
        word = strtok(sentence,delim);
        word != NULL;
        word = strtok(NULL,delim)
    )
        nCount = nCount + 1;
    return nCount;
}
http://liveworkspace.org/code/e309cd...c82238c3e22715
1
      ,      
 
- , ,
-
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
@Mail.ru