Error: 0xC0000005

Hi!

Since a few days I have had a new problem with my code. Before everything worked fine. Once the IDE crashed while I was running my program. OK, I started it again and loaded the project. After then the code doesn't work fine. The code is the same like before (I think....). But now I got an erro while running.
Error: 0xC0000005

My code:

main.cpp
1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include "bwt.h"

main(){
    bwt();
 

    return 0;
}


bwt.h
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
#ifndef BWT_H_INCLUDED
#define BWT_H_INCLUDED
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <algorithm>
using namespace std;
void selectionSort(string [], int);

string bwt()
{

    ifstream bemenet("be.txt");
    string szoveg,a;

    char c;
    szoveg.clear() ;
    while( szoveg.size() < 150 && bemenet.get(c) ){
            szoveg += c ;}


    string s=szoveg+"$";
    int n=s.size();
    string tablazat[n];


    for(int i=0;i<n;i++){
    a=s.back()+s;
    tablazat[i]=a.erase(n,1);
    s=tablazat[i];
    }

    selectionSort(tablazat,n);
   ofstream kimenet("tmp.tmp");
    for(int a=0; a<n;a++){
        s=tablazat[a];
        kimenet<<s.back();
    }


}

void selectionSort(string name[], int elems)
{
	int startScan, minIndex;
	string strName;
	for(startScan = 0; startScan < (elems - 1); startScan++)
	{
		minIndex = startScan;
		strName = name[startScan];
		for(int index = startScan + 1; index < elems; index++)
		{
			if(name[index] < strName)
			{
				strName = name[index];
				minIndex = index;
			}
		}
		name[minIndex] = name[startScan];
		name[startScan] = strName;
	}
}



#endif // BWT_H_INCLUDED



Could somebody help me?

Thank you!
This would be a very simple Burrows-Wheeler transformation.
I searched simple codes, but I didn't find, so I wrote that what worked well untill now.

Is there any other simple code for that?
The error may be because of a number of reasons. It represents an access violation -- some part of some program on your system is trying to access memory it does not have permission to.

I'm not sure what you are trying to do with tablazat[], but you can use the std::rotate() <algorithm> to do the same.

Line 25: VLAs are not legal in C++. If your compiler is letting you do this then it may also be the problem?

Line 48: Why are you not sorting the final element? ("edcba" --> "bcdea")

Other issues:
You are defining functions in a header file. Don't do that. Headers only exist to tell you what functions exist in another .cpp file.

Here's some reading about headers and sources to help.
http://www.cplusplus.com/faq/beginners/multiple-sources/

Hope this helps.
Topic archived. No new replies allowed.