C ++句子的逆序

时间:2014-02-14 11:35:20

标签: c++ pointers

我正在尝试完成一个项目,但是我无法将句子的顺序颠倒过来。该项目要求使用500个字符的缓冲区,其中用户输入的字符数组将从用户输入数组存储到500个字符的缓冲区中。用户按下后的每一行输入一个空的'\ 0'字符需要被添加来代替'\ n'。还必须创建一个指针数组来存储用户输入的每个句子的第一个值。现在我正在尝试弄清楚如何读取字符,直到它在500的缓冲区中将其存储为变量中的空值,然后移动到下一组字符,直到它达到null然后交换它们直到它们达到c字符串的结尾。 这是我到目前为止编码的内容。

#include <iostream>
#include <string>
#include <cstring>

using namespace std;  

const int BUFFER = 500;  
const int POINTERS = 50;  
const int N = 30;  
const int HALF = 2;  

int main()  
{  
    char sentences[BUFFER];  
    char *pointers= new char[POINTERS];  
    int count = 0;  
    int index = 0;  
    char userInput[N];  

    do  
    {  
        int i = 0;  
        cout << "Enter in sentences: ";  
        cin.getline(userInput, N);  

        int length = strlen(userInput);  

        *(pointers + index) = userInput[0];  

        if (*(pointers + index) == '0')   
            *(pointers + index) = '\0';  

        index++;  

        *(pointers + index) = '\0';  

        do  
        {  
            sentences[count] = userInput[i];  
            count++;  
            i++;  
        } while (userInput[i] != NULL);  

        sentences[count] = '\0';  
        if (sentences[count] == '\0')  
            count++;  
        if (sentences[count - 1] == '0')  
            sentences[count - 1] = '\0';  
        i = 0;  
    } while (*userInput != '0' &&  *sentences < BUFFER);  

    system("pause");  
    return 0;  
}  

0 个答案:

没有答案
相关问题