C ++:for循环无法按预期工作

时间:2019-05-22 06:50:12

标签: c++

#include <iostream>    
#include <fstream>

using namespace std;    

void input (char*);    
void processing (char*);

char *array = new char [2000];


int main ()
{   
    input (&array [0]);
    processing (&array [0]);

    return 0;    
}

void input (char* input)
{
    ifstream in;
    int index = 0;
    in.open ("input.txt");

    while (in.get (input [index]))
    {
        index++;
    } 

    in.close();
    in.clear();
    cout << input;
}

void processing (char* start)
{
    ofstream out;
    int flag = 0;    
    int eos = 0;    
    out.open ("output.txt", ios::app);    
    for (int index = 0; start [index] < '\0'; index++)    
    {    
        out << start [index];    
        cout << start [index];    
        if (flag == 0)    
        {    
            eos = index;    
            flag = 1;    
        }    
        else if (start [index] == ' ')    
        {    
            out << "    ";    
            cout << "   ";    
            for (int index1 = eos; start [index1] < ' '; index1++)    
            {    
                out << start [index1];    
                cout << start [index1];

                if (start [index1] == 's'  && start [index1 + 1] == ' ' || start [index1 - 1] == 'c' && start [index] == 'h' && start [index1 + 1] == ' ' || start [index1 - 1] == 's' && start [index] == 'h' && start [index1 + 1] == ' ')    
                {    
                    out << "es";    
                    cout << "es";    
                    break;    
                }

                if (start [index1] == 'y' && start [index1 + 1] == ' ')    
                {    
                    out << "ies";    
                    cout << "ies";    
                    break;    
                }

                if (start [index1 + 1] == ' ')    
                {    
                    out << "s";    
                    cout << "s";    
                    break;    
                }    
            }    
            out << endl;    
            cout << endl;    
            flag = 0;    
        }    
    }

    delete [] start;    
    start = NULL;    
    out.close ();     
}

样本输入文件:

chair dairy boss fly

预期的输出文件:

chair      chairs
dairy     dairies
boss       bosses
fly         flies

实际结果,输出文件中没有输出

chair dairy boss fly

0 个答案:

没有答案
相关问题