繁体   English   中英

ESP调用约定问题C ++

[英]ESP calling convention issues C++

对于家庭作业,我应该读取一个文件并对字符串进行排序。 为此,我正在使用选择排序,它可以工作。 现在,在调用selSort函数后,它立即崩溃。 我已经没有解决这个问题的想法了,谁能帮助我?

// 2_8.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>
#include <wchar.h>
#include <fstream>
#include <iostream>
using namespace std;

class convert
{
private:
    ifstream myFile;
    TCHAR charArray[1000][25];
    int size;

public:
    convert()
    {
        myFile.open("rand.txt");
        for(int x=0;x<1000;x++)
        {
            for(int y=0;y<25;y++)
            {
                charArray[x][y] = NULL;
            }
        }
        if(!myFile)
        {
            cout << ("File not open") << endl;
        }
        else
        {
            cout << ("File opened") << endl;
        }
    }

    void readFile()
    {
        int x = 0;
        int y = 0;
        int result =0;

        if(myFile.is_open())
        {
            TCHAR tempChar;
            while(!myFile.eof())
            {
                tempChar = myFile.get();
                if(tempChar != 32)
                {
                    charArray[x][y++] = tempChar;
                }
                else
                {
                    size=x++;
                    y = 0;
                }
            }
        }
        result = selSort(charArray,size);

        if(result)
        {
            cout << "We did it!!!!";
        }
    }

    void printString()
    {
        for(int x=0;x<1000;x++)
        {
            for(int y=0;y<25;y++)
            {
                cout << charArray[x][y];
            }
            cout << endl;
        }
    }

    int selSort(TCHAR thArray[][25], int length)
    {
        TCHAR tempArray[1][25];


        for(int x=0;x<1;x++)
        {
            for(int y=0;y<25;y++)
            {
                tempArray[1][25] = NULL;
            }
        }
        for(int x=0;x<length;x++)
        {
            int best = 0;

            for(int y=1;y<length;y++)
            {
                int result = _tcscmp(thArray[y],thArray[best]);
                if (result == 1)
                {
                    best = y;
                }
                for (int t=0;t < _tcslen(thArray[best]);t++)
                {
                    tempArray[0][t] = thArray[best][t];
                }
                for(int w=0;w < _tcslen(thArray[x]);w++)
                {
                    thArray[best][w]=thArray[x][w];

                }
                for(int e=0;e < _tcslen(thArray[x]);e++)
                {
                    thArray[x][e]=tempArray[0][e];

                }
            }
        }
        return 1;
    }
};
int _tmain(int argc, _TCHAR* argv[])
{
    convert c1;

    c1.readFile();

    system("pause");
    return 0;
}
int selSort(TCHAR thArray[][25], int length)
{
    TCHAR tempArray[1][25];

    // ...

    tempArray[1][25] = NULL;   // In the for loop
 }

tempArray中没有第二行。 如果数组有n行,则其索引从0到n-1开始 可能是您的意思-

tempArray[x][y] = NULL;

除了编写循环外,还可以使用位于算法标头中的std :: fill函数来用唯一元素填充数组元素。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM